In article <3f***********************@dread16.news.tele.dk> ,
"Lasse Skyum" <no spam> wrote:
Is it true that when std::vector resizes for more capacity it copies all the
elements to a bigger array and then destroys all the elements from the old
one?
Yes.
If so, why doesn't it just use realloc for possible resizing of the existing
memoryblock??
The most fundamental reason is that in general vector's contained
element can not be copied using memcpy (as realloc threatens to do).
Instead the element's copy constructor must be used.
That being said, I believe it is a worthwhile goal to teach vector to
attempt to expand in place when it needs to increase its capacity.
-Howard