Bridges > COM Export Bridge > Multidimensional Array Storage and Access > Why Storage and Access Matter

# Why Storage and Access Matter

Clients that need to pass an array to IDL need to understand the memory layouts of the arrays in order to know if they should convert arrays from one format to the other. Simply trying to understand which format is “row” and which is “column” major is not enough because the definitions of those terms can differ in context.

Understanding these distinctions are critical when programming in Visual Basic and C++ as each language natively stores arrays differently. However, using the Win32 Safearray APIs, either directly or indirectly through the ATL wrapper classes, allows C++ code to create safe arrays in the same order as Visual Basic. However, C++ has the flexibility to create safe arrays ordered differently, which is useful for testing.

In summary:

- SAFEARRAYs and IDL arrays are stored differently and must be converted to be used by each other
- Multidimensional SAFEARRAYs are stored as “column major” in linear memory (i.e., a column is stored contiguously in memory)
- IDL stores multidimensional arrays as “scanline major” (i.e., stores each scanline contiguously in memory)
- All the Win32 APIs and ATL safe array wrapper classes access SAFEARRAYs in column major
- Visual Basic accesses SAFEARRAYS as “column major”
- Native C++ arrays are stored and accessed as “row major”