Lets say we have 1 million elements stored in our std::vector<T>
, its capacity is full.
Now I just want to add 1 element in it. According to concept of vector, now vector's capacity will be doubled in the new memory in heap and all 1 million elements will be copied to new memory location.
This seems to be a huge task.
Is here there any way that I can avoid this copying and add this new element in the next location only?
Nothing. I cant think of any method to avoid. Most developers suggested me use another container.