how to determine if a memory organization follows row major order or column major order?

204 views Asked by At

How to determine if a memory organization follows a row-major order or column-major order? I learned this new concept and got to know that if we know what a memory organization follows a row-major order or column-major order , we can make our array run in such a way that the performance of code increases by decreasing the number of page faults. But I am not able to find out "How to determine if a memory organization follows a row-major order or column-major order?".

1

There are 1 answers

1
Mark Setchell On BEST ANSWER

It depends, to some extent, on the language you use... which you didn't state.

You can test by creating a 2-row 3-column array and assuming it will be stored in row-major order, then checking. So create this:

0 1 2
3 4 5

Now look at the bytes in memory. If they go:

0 1 2 3 4 5

it is in row-major order. If they go:

0 3 1 4 2 5

your program uses column-major order.

Normally, C uses row-major ordering and fortran uses column-major ordering. I said it depends "to some extent" because with Python, for example, you can specify either ordering and even mix them on a case-by-case basis in the same program.