Memory Resize Function

Lets say contiguous memory is not available for vector's elements and it is occupied by something else. How does the resize function of vector allocate memory to be contiguous allocation?

Questions by Keyurpatel80   answers by Keyurpatel80

Showing Answers 1 - 3 of 3 Answers

The allocate method of the vector's Allocator is invoked to allocate the new space, the vector's content is copied to the newly allocated memory block, and then the deallocate method of the vector's Allocator is invoked to release the old memory block.

The vector is assigned an Allocator in its constructor. If no Allocator is provided when the vector is created (by far the most common case), the default allocator class template is instantiated for the vector content type and assigned as the vector's allocator. This default allocator uses ::operator new to allocate and ::operator delete to deallocate memory.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions