Get the latest tech news
Leveraging Zig's Allocators
How Zig's allocators can help manage memory and improve performance
We could structure our API so that the action has to write() the response and thus be able to free any allocations it made, but that would make it impossible to add some features, like supporting middleware. An ArenaAllocator is a great option for an HTTP server because they're bound to a request, which has a well defined/understood lifetime and is relatively short lived. To keep this somewhat simple, I left out the implementation of free- which is OK in this specific case since "primary" is going to be a FixedBufferAllocator and "fallback" is going to be an ArenaAllocator(thus, all the freeing happens when the arena's deinit or reset are called).
Or read this on Hacker News