multi vs single dimensional array

Hi all,

Has anyone compared efficiency of accessing fixed size multidimensional array vs single dimension array? Which one is faster and requires less cpu?

ex: read position x, y

result = array2D[y][x];
result = array1D[y*width + x];

thanks
Use a 2D array,after all the compiler knows better.An optimized compiler will always generate the same binary code for both notations,but the first one is more clear and readable.I think the only good excuse to use the second one is when you want to overload the operator() to enable a syntax with () like on array2D(x,y).Cheers.
The efficiency should largely be the same, so long as width is a compile-time constant.

Though I don't unilaterally agree with the statement to always use a 2D array.
Topic archived. No new replies allowed.