How are 2D static arrays allocated?

Jesse Phillips jessekphillips at gmail.com
Tue Nov 4 15:50:25 PST 2008


On Tue, 04 Nov 2008 01:34:26 -0500, Jarrett Billingsley wrote:

> On Mon, Nov 3, 2008 at 11:30 PM, Jesse Phillips
> <jessekphillips at gmail.com> wrote:
>> In C allocating a static 2D array gives a continues chunk of memory.
>> Java creates an array that points to more arrays. Just wondering how D
>> handles this.
> 
> If it's a 2D fixed-size array, like:
> 
> int[5][6] x;
> 
> Then it is allocated as a single chunk of memory, and when you index it,
> it calculates the offset into that block of memory.
> 
> But 2D dynamic arrays:
> 
> int[][] y;
> 
> Are handled like in Java - an array of arrays.  When you index it, it
> indexes the first array, then indexes the second array.

Thanks, I figured it would work like this be it for C compatibility or 
not.


More information about the Digitalmars-d-learn mailing list