When erase() is called on a vector for instance, what happens in terms of memory deallocation?
I'm doing an exercise question which is based on a simplified user-implementation of the vector container and it's gotten me to implement an erase() operation for the container based on the standard erase(). So I've written an erase() which takes a single iterator and overloaded it to take a range and they erase the required elements OK.
But I'm wondering what to do about deallocating memory after the erase. This container takes a simplified approach to allocation: once preallocated memory is exhausted, a new amount is allocated which is twice the current size. I'm guessing this isn't how the library vectors work though??
My question is, is it an acceptable strategy to deallocate all of the unused memory after every erase(), or is this too inefficient? Should I for instance wait until the unused memory consists of more than half the total memory before deallocating it (which would I guess be the opposite of the allocation strategy)? Or am I barking up entirely the wrong tree? This is all new ground for me!