resizeable arrays: T[new]

Ary Manzana ary at esperanto.org.ar
Mon Jun 4 18:48:17 PDT 2007


Walter Bright escribió:
> 
>    T[n]   a;  // static array
>    T[]    b;  // dynamic array
>    T[new] c;  // resizeable array
> 
>    a.length = 6;   // error, static array
>    b.length = 6;   // error, dynamic array is not resizeable
>    c.length = 6;   // ok
>    b = c;          // ok, implicit conversion of resizeable to dynamic
>    c = b;          // error
>    c = b[0..n];    // error
>    b = c[0..n];    // ok, but watch out if c is later resized
>    b = c[0..n].dup; // ok, no worries
>    c = cast(T[new])b; // ok, but this will be deliberate

I don't understand how dynamic arrays work with this change.

T[] b;        // b is a dynamic array of size... ???
b.length = 6; // error, dynamic array is not resizeable ????????

So maybe this should be:

T[] b = new T[6]; // ... of size 6, and 6 can
                   // be replaced with a dynamic variable

Is this the intention of it?

I've only wrote one program in D, and I used dynamic arrays as lists 
(AKA ArrayList in Java). So I guess my program will break with this 
change, because I can't concatenate anymore. Maybe I've been using 
dynamic arrays in the wrong way?



More information about the Digitalmars-d-announce mailing list