T[new]

Walter Bright newshound1 at digitalmars.com
Sun Aug 9 13:58:15 PDT 2009


grauzone wrote:
> will
> 
> T[new] a;
> 
> allocate something?

Nope.

> Or will the allocation of the hidden library array 
> object delayed until the length is set to non null?

Yes.

> If the library array 
> object is not allocated, will a.ptr, a.capacity and a.length simply 
> return null?

Yes. Clearly, those properties will have to be functions under the hood. 
So T[new] operations will be a bit slower than for slices. For faster 
indexing, you'd probably want to do:

auto slice = a[];

and then operate on the slice.



More information about the Digitalmars-d mailing list