pointers, assignments, Garbage Collection Oh My?

JohnnyK johnnykinsey at comcast.net
Wed Jul 10 11:38:40 PDT 2013


On Wednesday, 10 July 2013 at 18:22:24 UTC, Ali Çehreli wrote:
> 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

Reminds me of how Delphi (aka Pascal) strings are work.  Thanks 
everyone this answers some of my questions.  Now what about when 
the return type of a function is a string?  Is D returning the 
pointer to the string structure or is it returning the structure?


More information about the Digitalmars-d-learn mailing list