
On Aug 19, 2013, at 9:44 AM, Thorsten Ottosen
On 19-08-2013 15:10, Larry Evans wrote:
On 08/19/13 07:54, Larry Evans wrote:
On 08/19/13 06:59, Thorsten Ottosen wrote:
cont.push_back<Derived>( x, y );
Using a templated push_back, IIUC, would require some sort of container, such as std::vector<char> cont, which contains contigous storage, and the push_back should find the next location, i_aligned, in std::vector<char> which is at alignment, alignof(Derived). and would then push_back i_aligned chars, then further push_back sizeof(Derived) char's, the new inplace at cont.begin()+i_aligned.
Does that make sense?
OOPS. If all those push_back's of a char causes the vector to be resized in placed in a different location, then wouldn't that require all the realignments for each element to be recalculated :(
Reallocation causes a bigger problem...
Hmmm. Not if &cont[0] is stored at a max aligned location, which I assume it would be since the storage would be created on the heap with new[] which, according to the c++ standard ( can't remember which page or section), returns a maximally aligned storage location.
Exactly. The relative locations should stay the same, only the start address would change.
Sure, the new objects would be laid out in memory the same after a reallocation, but...
And since the start of cont is maximally aligned, any offsets in that cont with a given alignment would have the same alignment when moved, IIUC.
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. 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. I should think a deque would be better as it doesn't require all of that work. ___ Rob (Sent from my portable computation engine)