-
Book Overview & Buying
-
Table Of Contents
Systems Programming with Zig
By :
The allocator model in Zig is not just a design preference; it reflects a fundamental philosophy about where complexity should live in a systems program. In most languages, the allocator is a global, invisible service that the runtime manages on your behalf. This convenience comes at a cost: you cannot easily change allocation strategy per subsystem, you cannot trivially detect leaks in a specific code path, and you cannot run the same logic against a stack buffer in one context and the system heap in another without rewriting it. Zig eliminates the global allocator entirely. Every function that needs dynamic memory declares that need explicitly by accepting a std.mem.Allocator parameter. The function does not know or care whether the bytes it receives came from the OS heap, a pre-allocated arena, or a fixed array on the stack. That decision belongs to the caller, who is the only party with enough context to make it correctly. The std.mem.Allocator...