Improved vector container. Updated version of the project - simple-vector
Read in other languages: English, Русский
This project is a continuation of the project simple-vector - of a simplified analogue of the standard container vector. The project has been redesigned to improve the effectiveness of methods and expand functionality.
To build this project on linux you need:
- If you don't have Cmake installed, install Cmake
- If the "Debug" or "Release" folders are not created:
mkdir Debug
mkdir Release
- Run the command for Debug and/or Release conf:
cmake -E chdir Debug/ cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Debug
cmake -E chdir Release/ cmake -G "Unix Makefiles" ../ -DCMAKE_BUILD_TYPE:STRING=Release
- Go to "Debug" or "Release" folder and build:
cmake --build .
- To Run program - in the debug or release folder run:
./advanced_vector
- C++17(STL)
- GCC (MinG w64) 11.2.0
- new placing operator
- new and new[] operators, delete and delete[] operators
- Exception handling
- Three levels of exception security
- Working with uninitialized memory area:
- Installation and configuration of all required components in the development environment to run the application
- The use case and tests are shown in main.cpp .
- Size
- Capacity
- operator[]
- operator=
- Swap
- Resize
- Reserve
- PushBack
- PushBack
- PopBack
- EmplaceBack
- begin
- end
- cbegin
- cend
- Emplace
- Erase
- Insert
RawMemory
is responsible for storing a buffer that holds a specified number of elements, and provides access to elements by index
Benchmark of the previous version of the container- SimpleVector
и std::vector
:
SimpleVector:
After construction: Def ctors: 11, Copy ctors: 0, Move ctors: 0, Copy assignments: 10, Move assignments: 0, Dtors: 1
After push: Def ctors: 31, Copy ctors: 0, Move ctors: 0, Copy assignments: 21, Move assignments: 0, Dtors: 11
After destruction: Def ctors: 31, Copy ctors: 0, Move ctors: 0, Copy assignments: 21, Move assignments: 0, Dtors: 31
std::vector:
After construction: Def ctors: 10, Copy ctors: 0, Move ctors: 0, Copy assignments: 0, Move assignments: 0, Dtors: 0
After push: Def ctors: 10, Copy ctors: 1, Move ctors: 10, Copy assignments: 0, Move assignments: 0, Dtors: 10
After destruction: Def ctors: 10, Copy ctors: 1, Move ctors: 10, Copy assignments: 0, Move assignments: 0, Dtors: 21
The difference in the number of constructors called and assignment operations is caused by the fact that when performing a PushBack on a filled container, SimpleVector not only allocates twice the amount of memory in the heap, but also initializes it with default values. This is a feature of the operation new[]. Then the array values from the previous memory area are copied, so new values are assigned to the elements.
The current version of the container uses the placing operator new and working with raw memory.
The code Benchmark of the current version is in the file main.cpp , when the program starts, after passing the tests, Benchmark is output.