Explicit Allocation
- The allocator parameter. Anything allocating takes an allocator argument: heap use visible in every signature.
- alloc and free. Memory returns through alloc and leaves through free: with defer pairing them on the same screen.
- No global allocator. Zig ships no blessed global allocator: the choice is yours, per program, per subsystem.
Allocator Interfaces
- The Allocator interface. Allocator is a standard interface: code written against it runs on any strategy.
- GeneralPurposeAllocator. The general-purpose allocator detects leaks and use-after-free in debug: a sanitizer built in.
- Arenas and fixed buffers. Arena allocators free everything at once; fixed buffers allocate from a stack array: strategies as values.
Designing Memory Ownership
- Ownership documented. APIs document who frees: the caller, the callee, or the arena that outlives both.
- Arena per task. Request-scoped work uses an arena: allocate freely, free once, leaks impossible by shape.
- Testing allocators. Tests run under the testing allocator: leaks and double-frees failing the suite loudly.
Before and after this level
- Before: Level 2: Pointers & Memory: Pointers, Slices, Memory Representation.
- Next: Level 4: Structs, Enums & Unions: Structs, Enums, Tagged Unions.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Zig Level 3: Allocators cover?
Explicit Allocation, Allocator Interfaces, Designing Memory Ownership: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 2: Pointers & Memory, which covers Pointers, Slices, Memory Representation.