NOTE
2.2 Main Memory
Main memory as byte-addressable volatile storage, endianness, alignment, locality, and its place between CPU caches and persistent storage.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is Main Memory?
Main memory (typically DRAM) stores code and data used by running programs.
From software’s perspective, memory is commonly modeled as a byte-addressable space. The operating system and MMU add virtual-address translation on top of physical memory.
2. Why Memory Is Needed
Registers are extremely limited in capacity. Main memory provides much larger working storage for:
- program code;
- stacks and heaps;
- runtime metadata;
- page cache and kernel structures;
- application data.
3. Endianness
For a multi-byte value, endianness describes how its bytes are ordered in memory.
Big-Endian
The most significant byte is stored at the lowest address.
Little-Endian
The least significant byte is stored at the lowest address.
x86-64 is little-endian. AArch64 systems are typically operated in little-endian mode as well, though the architecture has broader capabilities.
Endianness matters for binary protocols, file formats, serialization, and low-level memory inspection.
4. Alignment
Many data types are placed at addresses aligned to particular boundaries. Alignment can simplify or accelerate hardware access and influences struct padding and memory layout.
Misaligned accesses are handled differently across architectures and instructions; they may be legal but slower, or restricted in some cases.
5. Main Memory and Cache
CPUs normally access memory through a hierarchy of caches rather than going to DRAM for every load/store.
See CPU Cache.
The key performance property is therefore not only DRAM latency, but also whether the working set fits in caches and exhibits good locality.