Dynamic arrays

qznc via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Sep 1 00:43:40 PDT 2015


On Monday, 31 August 2015 at 22:03:07 UTC, jmh530 wrote:
> In general, I find myself very easily getting mixed up by the 
> syntax of the static vs. dynamic arrays. For instance, compare
> int[] x = new int[3];
> int[3] y = new int[3];
> auto z = new int[3];
> x and y are obviously dynamic and static arrays, respectively. 
> However, my initial guess on z is that is like y, a static 
> array on the heap. But that is wrong. It's actually like x. 
> Easy to get confused.

In general, "new" means heap allocation.

I wonder about the initialization of y. Maybe it creates a 
temporary dynamic array on the heap and then copies it to the 
static array on the stack?


More information about the Digitalmars-d-announce mailing list