Thread overview
Array and Memory
Jul 22, 2004
Pac
Jul 23, 2004
Ben Hinkle
Jul 23, 2004
Derek Parnell
Jul 23, 2004
J Anderson
Jul 24, 2004
J Anderson
Jul 26, 2004
Norbert Nemec
July 22, 2004
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
July 23, 2004
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

July 23, 2004
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
July 23, 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
>  
>


-- 
-Anderson: http://badmama.com.au/~anderson/
July 24, 2004
> 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.


July 24, 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.

-- 
-Anderson: http://badmama.com.au/~anderson/
July 24, 2004
ah, i didn't see the "as well".


July 26, 2004
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.