Now there are four ways to create/use "arrays" in D2:
- the * syntax on a raw memory block, like in C.
- fixed sized arrays, that are just a pointer somewhere. they may even become 
fully value types........
- the slice struct, about 2 * size_t.sizeof
- the new reference arrays, a pointer on the stack, plus a 3 items struct 
somewhere, probably on the heap. If it doesn't escape the scope LDC may be able 
to put it too on the stack. The GC may allocate a space of 4 items anyway for 
it, so there's an item wasted.
:-)
In the meantime I have understood that the slice has to be the default syntax 
to keep the compatibility with C :-)


Walter Bright:

> 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.

Let's hope such functions can be inlined. Assuming they can be inlined, a smart 
compiler can remove some of those ifs where it knows the array surely exists 
(virtual machines today are usually able to remove some array bound tests using 
similar tricks). I don't hold my breath for D2 to become this smart...

Bye,
bearophile

Reply via email to