T[new] misgivings
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Oct 16 07:12:56 PDT 2009
Max Samukha wrote:
> On Fri, 16 Oct 2009 14:25:44 +0200, Don <nospam at nospam.com> wrote:
>
>> Yes, but you could allocate the data immediately after the Array
>> structure, so you only have one allocation. And in the common case,
>> where it never exceeds the original capacity, they stay together and
>> preserve cache locality.
>>
>> void *data; // = &raw_data;
>> size_t length;
>> size_t capacity; // = 512
>> ubyte[512] raw_data;
>
> Great! And if the length later exceeds the capacity, try to reallocate
> in place. If impossible, allocate a new block, copy the data, adjust
> the data pointer and shrink the original block to the size of the
> Array struct. Right?
That's the idea. The only problem that Walter pointed out was that
moving GCs may have a problem with internal pointers.
Andrei
More information about the Digitalmars-d
mailing list