Code Monkey home page Code Monkey logo

cpp-advanced-vector's Introduction

cpp-advanced-vector

Improved vector container. Updated version of the project - simple-vector

Read in other languages: English, Русский

Program Description

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.

Build using Cmake

To build this project on linux you need:

  1. If you don't have Cmake installed, install Cmake
  2. If the "Debug" or "Release" folders are not created:
mkdir Debug
mkdir Release
  1. 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 
  1. Go to "Debug" or "Release" folder and build:
cmake --build .
  1. To Run program - in the debug or release folder run:
./advanced_vector

System requirements:

  1. C++17(STL)
  2. GCC (MinG w64) 11.2.0

Stack of technologies:

  1. new placing operator
  2. new and new[] operators, delete and delete[] operators
  3. Exception handling
  4. Three levels of exception security
  5. Working with uninitialized memory area:

Before you start:

  1. Installation and configuration of all required components in the development environment to run the application
  2. The use case and tests are shown in main.cpp .

Detailed description of the project:

Methods supported by the current version of the container:

  • 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

Description of differences from the previous version

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.

cpp-advanced-vector's People

Contributors

zakharovyuriy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.