Top 3 Language Defaults: C/C++, Fortran, NumPy

C/C++ and Python's NumPy library predominantly use row-major order (C-contiguous), storing rows contiguously in memory, while Fortran and MATLAB default to column-major order (F-contiguous), storing columns contiguously.

The top 3

  1. C/C++ vs. Fortran: Memory Layout Origins: C/C++ inherited row-major order from its predecessor B, while Fortran's column-major choice dates back to early IBM machines and efficiency in mathematical operations.
  2. Cache Performance: Default Access Impact: Accessing elements along the default memory layout (row-wise for C/C++, column-wise for Fortran) maximizes cache hits, leading to significantly faster processing compared to misaligned access.
  3. NumPy's Memory Layout Flexibility: NumPy arrays default to C-contiguous (row-major) but allow explicit creation or conversion to Fortran-contiguous (column-major) arrays, optimizing performance when interfacing with Fortran libraries or specific algorithms.

Sources

Open the full topic