www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Array and Memory

reply Pac <Pac_member pathlink.com> writes:
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
next sibling parent reply 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
parent 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
prev sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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/
Jul 23 2004
parent reply "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
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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/
Jul 23 2004
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
ah, i didn't see the "as well".
Jul 24 2004
prev sibling parent 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