Pointers & Memory
This is the branch where low-level either clicks or doesn't. A pointer is just an
address with a type; from that one idea comes everything that makes C fast and
everything that makes it dangerous. We go deep on the stack and the heap,
malloc/free, pointer arithmetic, struct layout, the classic bugs
(use-after-free, double-free, leaks, overflows), and writing your own allocators
so you stop treating memory as infinite and start managing it with intention.
Memory is not a detail the language hides from you here — it's the material you work in. Owning it means knowing who allocates, who frees, and what every byte of a struct is doing.
Planned notes
- What a pointer really is — an address with a type
- Pointer arithmetic and the type's stride
- The stack: frames, locals, and automatic storage
- The heap:
malloc/freeand the allocator underneath - Pointers to pointers (double indirection)
void*and type erasure- const-correctness and what
constreally promises - Function pointers
- Struct layout: alignment and padding
- Data layout and cache-friendliness
- Strict aliasing and type punning
- Classic bug: use-after-free and double-free
- Classic bug: buffer overflow and out-of-bounds access
- Classic bug: memory leaks and ownership discipline
- Custom allocators: arena, pool, and bump
Core sources
- Ulrich Drepper — What Every Programmer Should Know About Memory — the memory paper. https://www.akkadia.org/drepper/cpumemory.pdf
- CS:APP — dynamic memory allocation chapters — how
mallocactually works. https://csapp.cs.cmu.edu/ - Richard Reese — Understanding and Using C Pointers (O'Reilly) — pointers end to end. https://www.oreilly.com/library/view/understanding-and-using/9781449344535/
- Ryan Fleury — Untangling Lifetimes: The Arena Allocator — arena allocation as a design tool. https://www.rfleury.com/p/untangling-lifetimes-the-arena-allocator
- Doug Lea — A Memory Allocator (dlmalloc) and Dan Luu malloc writeups — real allocator internals. https://gee.cs.oswego.edu/dl/html/malloc.html · https://danluu.com/malloc-tutorial/
Connects to: C from the Metal · Machine Model · Assembly & Compiler Output · OS from Scratch