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).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of zig

zig

Photo of Allocators

Allocators

Related news:

News photo

I am not yet ready to switch to Zig from Rust

News photo

Zig's new CLI progress bar explained

News photo

Memory-mapped IO registers in Zig. (2021)