Contiguous memory places elements at adjacent addresses. Arrays of structs and primitive values can use this layout, helping keep related data local and reduce cache misses during access. section 2.8 section 6.1.1
In game data structures, layout affects how efficiently data can be traversed:
- A C# List stores values in an array, while a linked list’s nodes may be scattered across heap memory. Linked lists allow easy insertion and removal, but traversal can be slow. section 6.1.1
- Heap fragmentation can leave enough total free memory but no single contiguous region large enough for an allocation. Group related allocations and those with similar lifetimes, and release them together when possible. section 3.1
Fragmented arrays
Allocate arrays of 1 KB, 2 KB, and 1 KB; then delete the first and third. The two 1 KB holes total 2 KB, but neither can fit a 1.5 KB array. section 3.1
Figure 6.2 C# Lists use an array that is stored in a single contiguous block of memory, while Linked Lists allocate nodes wherever there is room, breaking data locality.

Compare the single-block storage of a C# List with linked-list nodes scattered across heap memory. section 6.1.1


