0

I have a few questions about how .Net stores multi-dimensional arrays in memory. I am interested in true multi-dimensional arrays not jagged arrays.

How does the Common Language Runtime (CLR) store multi-dimensional arrays? Is it in row-major, column-major, Iliffe vector or some other format?

Is this format required by the Common Language Infrastucture (CLI) or any other specification?

Is it likely to vary over time or between platforms?

7

1 Answer 1

3

This is in the specification ECMA-335 Partition I (my bold)

8.9.1 Array types

Array elements shall be laid out within the array object in row-major order (i.e., the elements associated with the rightmost array dimension shall be laid out contiguously from lowest to highest index). The actual storage allocated for each array element can include platform-specific padding. (The size of this storage, in bytes, is returned by the sizeof instruction when it is applied to the type of that array‘s elements.)

Section 14.2 also has more explanation.

These two sections specifically refer to arrays as opposed to vectors, the latter of which is the more familiar zero-based one-dimensional array used in most places.

Arrays on the other hand, can be multi-dimensional and based on any bound, they can also be one-dimensional.

So essentially, it's just one big array under the hood, and uses simple math to calculate offsets.


"Is it likely to vary over time or between platforms?" I'll get my crystal ball out... The spec can always change, and implementations may decide to derogate from it.

1
  • Thanks! It's good to know it's in the spec and not just an implementation detail.
    – andypea
    Aug 23, 2022 at 4:55

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.