5 Memory
This section starts from the hardware: what a stack is, what a heap is, and how each one hands out and takes back memory. R’s garbage collector and Rust’s ownership rules both build on that, so read this before either.
Most runtime decisions, from garbage collection strategy to how threads coordinate, depend on where values live in memory and how long they stay there.
After this section
- Explain the difference between stack and heap allocation
- Describe when each one is safe and why
- Connect memory layout to concurrency problems
- Explain how a GC strategy decides what threads must coordinate
The pages
Stack vs Heap. How each region allocates and frees memory, and what R keeps in each.
Pointers, References, and Object Identity. The vocabulary of addresses, indirection, and why copy-on-modify silently produces new objects.
Allocation and Object Layout. What allocators do, alignment and padding, and how SEXPREC headers determine object overhead.
Arenas, Pools, and Immortal Data. Bulk allocation strategies, and the immortal arena that lets several interpreters share R’s builtin constants.
Before this section
Start with Orientation.
Where this leads
Interpreter Fundamentals uses stack and heap allocation to explain call frames and value dispatch. R Runtime Internals shows you how R uses both.
Rust for Runtime Engineering encodes these properties into type rules that prevent memory errors. The section on Concurrency and Parallelism explains why shared memory creates problems that stack-local data avoids.
Virtual Memory and Pages explains page faults and demand paging. Caches and Bandwidth covers cache lines and false sharing. Reference Counting vs Tracing Collection covers GC strategies and cycle detection. Copy-on-Modify and Fork, Spawn, and Platforms explain copy-on-write semantics.