The physical size of a rectangular array in memory

In C, in the array they say A[2][3] the right-most index change led to the smallest shift of the memory address, i.e. elements were located in memory as A[0][0], A[0][1]...

Is the same true for rectangular arrays in .NET? If we have, say, an array a[2, 3] - these are elements located in memory like a[0, 0], a[0, 1]... ?

+6
source share
1 answer

The CLI Specification , Section 8.9.1, states:

The elements of the array must be laid out inside the array object in a series of lines (i.e. the elements associated with the right-most array must be dimensioned contiguously from the lowest to the highest index). The actual storage allocated for each element of the array may include platform-specific registration.

So, the answer is yes - first you will encounter all the elements of the first row, then with all the elements of the second row, etc. (as the spec says, this is called string order).

+14
source

Source: https://habr.com/ru/post/915606/


All Articles