digitalmars.D.learn - Re: How are 2D static arrays allocated?
- ore-sama <spam here.lot> Nov 07 2008
Jarrett Billingsley Wrote:You.. can't actually allocate a static array on the heap using new. At least not directly. It's kind of an embarrassing hole in the syntax. In fact, I'm not sure if you can even get a static array to point onto the heap, since a static array "reference" is treated like a value type when assigned to, so if you do something like: int b = (new int(1)); The weirdness on the right-hand-side is needed to get around the compiler "helpfully" rewriting "new int" as "new int(3, 4)". But this code will simply allocate a static array on the heap, and then copy its contents onto the stack. Dumb.
writeln(typeof(rg2).stringof); //int[10u] writeln(cast(size_t)&rg2-cast(size_t)&rg2); //40 As you can see it allocates contunous int and assigns it to dynamic array int. Which is nearly what topicstarter wants. Well, border checks will be dynamic for the first index.
Nov 07 2008