Systems Foundations · core
Program Memory Model
Pointers, stack frames, heap allocation, object lifetime, executable loading, and the transition from a program on disk to a running process.
Mental model
A pointer is a typed interpretation of an address inside a process virtual address space. Stack frames follow call lifetimes, heap allocations follow explicit or runtime-managed ownership, and the loader maps code and data into a process before execution begins.
How to study Program Memory Model
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use The Rust Programming Language — What Is Ownership? to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare Program Memory Model with Data Representation, Compute, Memory & Storage Hierarchy, Operating System Mechanics. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Trace a program into process memory and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Where it matters
Debugging crashes and leaks, understanding allocators and garbage collectors, designing FFI boundaries, reading profiles, and reasoning about process isolation.
Common mistakes
- Saying a pointer lives on the heap when only the allocation it references is on the heap
- Equating virtual addresses with stable physical memory locations
- Ignoring ownership and lifetime when memory crosses thread, callback, or process boundaries
Learn from primary sources
Practice and explain it back
Trace a program into process memory
Implement memoryMap() for this C-shaped program: static int requests; int main() { char *buffer = malloc(4096); int count = 0; serve(buffer, &count); free(buffer); }. Return executable, stack, heap, pointer, and process strings. Each must be a distinct explanation of at least six words that names its storage, lifetime, ownership, or loading mechanism.
Expected evidence: A five-part causal trace distinguishing the executable image, stack frame, heap allocation, pointer value, and running process virtual address space.
Open the interactive drill →Review prompts
- In char *buffer = malloc(4096), where do the pointer and pointed-to bytes live, who controls each lifetime, and what changes when the executable becomes a process?
Build evidence
Synthesize: Systems Foundations
Build a tiny HTTP/1.1 static-file server on raw TCP sockets without a framework or high-level HTTP server library. Parse requests, serve bounded files, handle partial I/O, inject failures, measure the result, and explain how the operating system, network, memory, concurrency, and storage paths interact.
- Accepts TCP connections, parses a bounded HTTP GET request, serves fixture files, and returns explicit errors for malformed requests, missing files, and path traversal attempts
- Names and implements a concurrency model with connection, request-size, timeout, and resource limits, including correct handling of partial reads and writes
- Injects at least a slow client, malformed request, or interrupted transfer and demonstrates bounded failure and recovery
- Reports a reproducible workload with throughput, p50/p95 latency, peak memory, and open-connection observations
- Explains the loader, process, syscall, buffer, filesystem, TCP, and scheduling path in a concise architecture note