T[new]

Brad Roberts braddr at puremagic.com
Sun Aug 9 13:36:58 PDT 2009


Yay.  What will happen with slices over a T[new] when the underlying T[new] must
be moved due to resizing?  The behavior needs to be at least well specified, if
not well defined.

Walter Bright wrote:
> D has a number of subtle problems (performance and semantic) that arise
> when arrays are resized. The solution is to separate resizeable array
> types from slices. Slices will retain the old:
> 
>    T[] slice;
> 
> syntax. Resizeable arrays will be declared as:
> 
>    T[new] array;
> 
> The new expression:
> 
>    new T[10]
> 
> will return a T[new].
> 
> T[new] will implicitly convert to T[], but not the other way.
> 
> slice.length will become read-only.
> 
> Under the hood, a T[new] will be a single pointer to a library defined
> type. This library defined type will likely contain three properties:
> 
>     size_t length;
>     T* ptr;
>     size_t capacity;
> 
> The usual array operations will work on T[new] as well as T[].
> 
> Doing this change will:
> 
> 1. fix many nasties at the edges of array semantics
> 
> 2. make arrays implementable on .net
> 
> 3. make clear in function signatures if the function can resize the
> array or not




More information about the Digitalmars-d mailing list