Rectangular array physical in memory order

后端 未结 1 1853
感动是毒
感动是毒 2020-12-20 12:45

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]...

相关标签:
1条回答
  • 2020-12-20 13:40

    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).

    0 讨论(0)
提交回复
热议问题