Rectangular Arrays

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sun Feb 25 12:03:10 PST 2007


Orgoton wrote:
> Bill Baxter Wrote:
> 
>> Orgoton wrote:
>>> You can declare a variable length array by doing something like
>>>
>>> int numbers[];
>>>
>>> //in runtime on the program:::
>>> numbers.length=size;
>>> //for bidimensionality:
>>> int table[][]; //or matrix
>>> table.length=HowManyCollumns;
>>> foreache (int[] row, table[]) row.length=HowManyRows; //or the size of the collumn
>>>
>>> See also:
>>> http://www.digitalmars.com/d/arrays.html
>>>
>>> Specially the dynamic array thingy. This is the best solution I have for you and I belive this one to be the simplest you got so far.
>> How is that simpler than
>>      auto table = new int[][](HowManyRows,HowManyColumns);
>> ??
> 
> To my opinion. Yours may differ. Creating buffers using .length is much more immediate than using new. Also, resizing the same buffers is much simpler. Sure the "foreach" stuff is cumbersome, but the OP mentioned he is learning D, so it'd be best if he gets the properties of (dynamic) arrays and the foreach (which is nothing more than a simplification of common for loops).

IIRC it's also pretty much exactly what 'new' will do internally (except 
it does it more generically). Do you always consider re-implementing the 
standard library "simpler"?


More information about the Digitalmars-d-learn mailing list