On Tuesday, 28 July 2015 at 17:26:39 UTC, Binarydepth wrote:
On Tuesday, 28 July 2015 at 17:07:47 UTC, Steven Schveighoffer wrote:
On 7/28/15 12:59 PM, Binarydepth wrote:

When indexing, it always goes out to in. So nam[0] is the first element of type int[2], and nam[0][0] is the first integer in that first element.

-Steve

I don't get what you mean here. In general I understood that in D multidimensional arrays are a group of arrays.

A bit off-topic.

I've done a lot of image processing work that deals with 2D arrays in particular. I must admit that for the most part now I just use a 1D array for all my 2D arrays and do a bit of index arithmetic to figure the location in 2D.

To index I have to do something like (for row major order):

my2darray[row * COLS_PER_ROW + col] = blah;

But I find this has many advantages:

1. The tiny bit of arithmetic is more than offset by not having to deal with trying to remember the order of the indices.

2. You can chose if you want row or column major order.

3. It makes lots of operations much easier, ie. adding two images together if they are of the same dimensions, generating histograms, calculating the average value in a 2D array.

4. Easy to set size dynamically.

5. Consistent between pretty much every programming language (ie. my C and D code would look the same).

6. (IMHO) Code is actually more readable. But then I find lots of brackets confusing ... so maybe its just me.






Reply via email to