Original Post
Hi. I want to extend of std::vector such that it never allows the amount of allocated memory to fall beneath a certain number of entries. I originally presumed that the reserve() method would allow the storage to shrink below its specified amount when items were removed, but now I'm confused.
Quote:That can't be right since pop_back allows a vector to dynamically shrink, right?
From codeproject.com However, the resize() member function is only capable of increasing the capacity of the vector. The only member capable of changing the size of the internal buffer is clear()
From /usr/include/c++/4.1.2/bits/stl_vector.h[/quote] So I suppose destroy() must re-size the memory. But _M_impl is an instance of allocator_type and std::allocator doesn't declare a destroy method... and it's asking a lot that the allocator instance should interpret the dynamic END of storage... so... what's going on? N.B. eyeballing "grep -r destroy *" doesn't indicate a destroy method defined ANYWHERE. At the end of the day, I want to put a persistant lower limit on the size of the allocated buffer, even if all its contents are popped or assign()ed to nothing. Since the allocator doesn't (depending on which spec you read) specify a resize() method in its interface, it's the container class that really needs to be changed -- but it's all starting to look like opaque magic. Oh woe.void pop_back() { --this->_M_impl._M_finish; this->_M_impl.destroy(this->_M_impl._M_finish); }