The Allocator Interface
One contract for all memory sources.
One Common Type
Every allocator in Zig is handed around as a single type, std.mem.Allocator. Your code talks to that one interface, never a concrete backend.
const Allocator = std.mem.Allocator;An Interface, Not a Class
std.mem.Allocator is a small interface: a pointer plus a table of functions. It describes what an allocator can do, not which one you use.
All lessons in this course
- Why Zig Has No Hidden Allocations
- The Allocator Interface
- alloc, free, create, destroy
- Dynamic Lists with ArrayList