How can I increment/decrement a multidemensional array without a loop?

H

Hendrix

Hi, I would like to pick four elements from a multidemensional array
and use the content of those elements. I want to do this without all
the subscript calls required for individual access, just want this for
speed. I know you can increment regular arrays via ++array or array++
etc. etc. but how do you do it with multidemensional arrays? lets say
I have array[x][y] and I need to access array[x+1][y+1] how can I do
this without the subscripts? The x and y count is at 64 by the way.

Thanks for any help.
 
I

Ivan Vecerina

Hendrix said:
Hi, I would like to pick four elements from a multidemensional array
and use the content of those elements. I want to do this without all
the subscript calls required for individual access, just want this for
speed. I know you can increment regular arrays via ++array or array++
etc. etc. but how do you do it with multidemensional arrays? lets say
I have array[x][y] and I need to access array[x+1][y+1] how can I do
this without the subscripts? The x and y count is at 64 by the way.

It's as simple as:
itemPtr += (rowLen+1);
Or in the case you mention:
itemPtr += 65;
Assuming that itemPtr points within: Item dataArray[64][64]; and
is in-range.

Note that, when starting to fiddle with item address calculations
in multi-dimensional arrays, I would recommend using a 1-dimensional
array and doing all offset calculations manually. While IIRC the
sub-arrays are supposed to be contiguous, using a consistent
approach should be preferred IMO.

hth,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top