## digitalmars.D - Array and Memory

• Pac (9/9) Jul 22 2004 Hello,
• Ben Hinkle (3/19) Jul 22 2004 linear. see http://www.digitalmars.com/d/arrays.html "Rectangular arrays...
• J Anderson (7/19) Jul 23 2004 Static arrays are rectangular (linear). Dynamic arrays are an array of
• Jarrett Billingsley (5/7) Jul 23 2004 hmm.. that would be somewhat inefficient if you were to add a column or
• J Anderson (11/21) Jul 23 2004 I think you miss-understood me. "as well" means "in addition" in my
```Hello,

I was wondering,
how much memory size is needed for a multidimensional array  like :

int[12][12] tab;

Are multidimensional arrays in D linearly implemented or is like in Java a first
array containing references to other arrays ?

If there is no linar implementation, do you intend to provide one ?

Best regards

Pac
```
Jul 22 2004
Ben Hinkle <bhinkle4 juno.com> writes:
```Pac wrote:

Hello,

I was wondering,
how much memory size is needed for a multidimensional array  like :

int[12][12] tab;

int.sizeof*12*12

Are multidimensional arrays in D linearly implemented or is like in Java a
first array containing references to other arrays ?

linear. see http://www.digitalmars.com/d/arrays.html "Rectangular arrays"

If there is no linar implementation, do you intend to provide one ?

Best regards

Pac

```
Jul 22 2004
Derek Parnell <derek psych.ward> writes:
```On Thu, 22 Jul 2004 20:04:25 -0400, Ben Hinkle wrote:

Pac wrote:

Hello,

I was wondering,
how much memory size is needed for a multidimensional array  like :

int[12][12] tab;

int.sizeof*12*12

Proof:
<code>

void main()
{
int[12][12] tab;
printf("int[12][12] tab;\n");
printf("int.sizeof*12*12; is %d\n", int.sizeof*12*12);
printf("      tab.sizeof; is %d\n", tab.sizeof);
}

</code>

--
Derek
Melbourne, Australia
23/Jul/04 10:11:40 AM
```
Jul 22 2004
```Pac wrote:

Hello,

I was wondering,
how much memory size is needed for a multidimensional array  like :

int[12][12] tab;

tab.sizeof

Are multidimensional arrays in D linearly implemented or is like in Java a first
array containing references to other arrays ?

Static arrays are rectangular (linear).  Dynamic arrays are an array of
references.  Personally I would like a rectangular arrays for dynamic
arrays as well.

If there is no linar implementation, do you intend to provide one ?

Best regards

Pac

--
```
Jul 23 2004
"Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
``` Personally I would like a rectangular arrays for dynamic
arrays as well.

hmm.. that would be somewhat inefficient if you were to add a column or
something.  if you added a row, it would only have to allocate room for one
more roaw at the end.  but if you added a column, it would have to allocate
enough room for a column, then copy each row over enough to make room for
the column.  not fun.
```
Jul 23 2004
```Jarrett Billingsley wrote:

Personally I would like a rectangular arrays for dynamic
arrays as well.

hmm.. that would be somewhat inefficient if you were to add a column or
something.  if you added a row, it would only have to allocate room for one
more roaw at the end.  but if you added a column, it would have to allocate
enough room for a column, then copy each row over enough to make room for
the column.  not fun.

I think you miss-understood me.  "as  well" means "in addition" in my
comment.

All depends what you use it for.  Certainly if its a vertex buffer then
its more efficient to use a rectangular array.  This is how I see it:

int [][] array; //dynamic array of arrays
int [,] array; //dynamic rectangular array.
int [width, ] array; //rectangular array with a fixed width

Note that rectangular arrays are possible with D, just not in a neat way.

--
```
Jul 23 2004
"Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
```ah, i didn't see the "as well".
```
Jul 24 2004
Norbert Nemec <Norbert.Nemec gmx.de> writes:
```J Anderson wrote:

Jarrett Billingsley wrote:

Personally I would like a rectangular arrays for dynamic
arrays as well.

hmm.. that would be somewhat inefficient if you were to add a column or
something.  if you added a row, it would only have to allocate room for
one
more roaw at the end.  but if you added a column, it would have to
allocate enough room for a column, then copy each row over enough to make
room for
the column.  not fun.

I think you miss-understood me.  "as  well" means "in addition" in my
comment.

All depends what you use it for.  Certainly if its a vertex buffer then
its more efficient to use a rectangular array.  This is how I see it:

int [][] array; //dynamic array of arrays
int [,] array; //dynamic rectangular array.
int [width, ] array; //rectangular array with a fixed width

Note that rectangular arrays are possible with D, just not in a neat way.

Note that my proposal in that direction is still in the pipe:

http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html

Walter seemed pretty much in favor of the idea in general, but made it clear
that it will be a past-1.0 issue.

I will continue refining the proposal as soon as I find the time. (Hopefully
in late summer.) There is a number of ideas that came up since the last
published version. Especially, the whole issue of array expressions needs
to be worked in.
```
Jul 26 2004