在内存中以便矩形阵列的物理矩形、阵列、内存、物理

2023-09-05 23:24:25 作者:ァ猥琐也是一种范

在C,在阵列说 A [2] [3] 最右边的指数的变化导致了最小的内存地址的转变,即元素被定位在内存中 A [0] [0],A [0] [1] ...

In C, in array say A[2][3] rightmost index change resulted in a smallest memory address shift, i.e. elements were located in memory as A[0][0], A[0][1]...

时同样适用于在.NET矩形阵列?如果我们有,说阵列 A [2,3] 是位于存储元件的 A [0,0],一个[0,1] ...

Is same is true for rectangular arrays in .NET? If we have, say array a[2, 3] are elements located in memory as a[0, 0], a[0, 1]...?

推荐答案

在 CLI规范,第8.9.1规定:

The CLI specification, section 8.9.1, states:

数组元素应进行布局数组对象中的行优先   顺序(即最右边的数组元素相关联   尺寸应当连续布局从低到高   指数)。分配给每个数组元素的实际寄存   包括平台特定的填充。

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.

因此​​,答案是肯定的 - 你会先遇到的第一个行的所有元素,第二行,等那么所有元素(如规范说,这就是所谓的行优先顺序排列的)。

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