Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

.net - Rectangular array physical in memory order

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...