
On 20-08-2013 11:04, Rob Stewart wrote:
On Aug 19, 2013, at 9:44 AM, Thorsten Ottosen
wrote:
Yes, at this level it is nice to take advantage of the memcopying built into vector<char>.
Here's the problem. Replicating the bits of and object isn't the same as copying it. Many classes store a this pointer or rely on a data member address as a unique key, etc. Copy constructors must run.
OK. :-) I was waiting for an expert to join the discussion.
If the container manages the reallocations by noticing when it is about to occur, creates a new vector with greater capacity, clones each element into the new vector, destroys the elements in the old vector, then swaps the two vectors, it can work.
Yeah, ok. I guess there will a need for one or two virtual functions in a base class after all. Copy-construction is one way, move-construction probably better.
I should think a deque would be better as it doesn't require all of that work.
Well, if we had a deque with better control over the chuck size, then perhaps. But I doubt it's a good idea. The container should of course have a reserve( unsigned words ) function as well as an shrink_to_fit() such that reallocations/memory use can be minimized. -Thorsten