T[new] misgivings
Max Samukha
spambox at d-coding.com
Fri Oct 16 06:24:07 PDT 2009
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?
More information about the Digitalmars-d
mailing list