• Advertisement
Sign in to follow this  

C++ Standard - data layout for multidimensional arrays

This topic is 1660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does the standard say anything about how the data in a multidimensional array should be arranged in memory? Is it required to be contiguous, etc?

 

I have no idea how to look this kind of thing up. A guy in my class threw std::random_shuffle() at a 2D array and VS didn't complain about buffer guards, so I ran it through myself and looked at the memory, and its storing it contiguously. I'm just wondering if this is standard or implementation specific.

Share this post


Link to post
Share on other sites
Advertisement
I don't have a reference, but AFAIK, they're defined to be just a contiguous 1D array (of size rows*columns) stored in row-major order.
int A[2][3] = { {1, 2, 3}, {4, 5, 6} };//two rows of 3 entries each.
int B[2*3] = { 1, 2, 3, 4, 5, 6 };//for each row, for each column, store item
assert( 0==memcmp( A, B, sizeof(int)*6 ) );
Edited by Hodgman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement