Reserve First
A short post about a coding pattern that is relevant for people who use the heap liberally and manage memory with their own hands.
Hasnain says:
“Zig applications should consider aborting on OOM. While the design goal of handling OOM errors correctly is laudable, and Zig makes it possible, I’ve seen only one application, xit which passes “matklad spends 30 minutes grepping for errdefer” test. For libraries, prefer leaving allocation to the caller, or use generative testing with an allocator that actually returns errors.
Alternatively, do as TigerBeetle. We take this pattern literally, reserve all resources in main, and never allocate memory afterwards:”
Posted on 2025-08-24T00:23:31+0000