On Wed, Jul 10, 2013 at 07:45:25PM +0200, Namespace wrote:
> >A string in D, and all arrays, is a struct looking like this:
> >
> >struct Array (T)
> >{
> >    T* ptr;
> >    size_t length;
> >}
> 
> I always thought it looks like this:
> 
> struct Array(T) {
>     T* ptr;
>     size_t length, capacity;
> }

Nope, the capacity is an attribute of the GC memory that the array is
pointing to, not the array "itself", which is merely a slice of this GC
memory.

When you append to an array, basically what happens is the GC is asked
"is this the end of the GC block and can we extend it please?" If it's
not the end of the GC block, a new block is allocated; otherwise, it is
extended, then the new data is written into it.


T

-- 
Those who've learned LaTeX swear by it. Those who are learning LaTeX swear at 
it. -- Pete Bleackley

Reply via email to