pointers, assignments, Garbage Collection Oh My?

Ali Çehreli acehreli at yahoo.com
Wed Jul 10 11:22:23 PDT 2013


On 07/10/2013 11:10 AM, Sean Kelly wrote:

 > On Jul 10, 2013, at 10:45 AM, Namespace <rswhite4 at googlemail.com> 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;
 >> }
 >
 > Sadly, no.  The only way to determine the capacity of an array is to 
query the GC.
 >

And to be pedantic, length comes first:

struct Array (T)
{
     size_t length;
     T* ptr;
}

Which is actually property-like because assigning to length does pretty 
complex stuff. So the member cannot be named as 'length':

struct Array (T)
{
     size_t length_;
     T* ptr;
}

Anyway... :)

Ali



More information about the Digitalmars-d-learn mailing list