From: Alan Bellingham (alan_at_[hidden])
Date: 2002-08-11 09:47:57
"Victor A. Wagner, Jr." <vawjr_at_[hidden]>:
>At Friday 2002/08/09 11:54, you wrote:
>>Or is it merely that it is not guaranteed to shrink a vector?
>not having the standard makes it difficult for me to know for sure, but
>given the wording in at least Nico's book, I inferred that it is guaranteed
>to NOT shrink it.
(220.127.116.11/6) The effect of calling std:vector<>::resize(), with a size
less than size(), is the same as calling erase for the range of elements
to be removed.
(18.104.22.168/3) std::vector<>::erase invalidates all iterators and
references /after/ the point of the erase.
Thus, resize() (when not growing the vector) mustn't invalidate
iterators to the elements that remain.
So unless you have some way of releasing only the end of the
contigiously allocated underlying memory back to the heap without
releasing all of it, you can't shrink the underlying memory using
A std::deque<> style std::vector<> would be able to do it, but that
would fall foul of the requirement for contiguous memory.
Whether resize(0)/erase(begin(), end()) could be allowed to drop all the
memory is interesting. I would say not, on the grounds that this would
-- Alan Bellingham (posting from home)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk