eknkc
I think the last sample needs a `fba.reset()` call in between requests.

BTW, I used zig a lot recently and the opaque allocator system is great. You can create weird wrappers and stuff.

For example, the standard library json parser will parse json, deserialize a type that you requested (say, a struct). But it needs to allocate stuff. So it creates an arena for that specific operation and returns a wrapper that has a `deinit` method. Calling it deinits the arena so you essentially free everything in your graph of structs, arrays etc. And since it receives an upstream allocator for the arena, you could pass in any allocator. A fixed stack allocator if you wish to use stack space, another arena, maybe jemalloc wrapper. A test allocator that checks for memory leaks.. Whatever.

gizmo
I'm not 100% sure how Zig allocators work but it looks like the arena memory is getting re-used without zeroing the memory? With slight memory corruption freed memory from a previous request can end up leaking. That's not great.

Even if you don't have process isolation between workers (which is generally what you want) then you can still put memory arenas far apart in virtual memory, make use of inaccessible guard pages, and take other precautions to prevent catastrophic memory corruption.

skybrian
Is there a reason why someone wouldn't use retain_with_limit or is doing without it just an exercise?
cageface
I have to admit I don’t really understand the problem Zig is trying to solve. If you’re not trying at the language level to address the core problems of C/C++, like Rust is, then it seems like you’re just making a more ergonomic version of those languages and that’s not enough to overcome how deeply entrenched they are.
sbussard
Has anyone here used zig with Bazel?
mikemitchelldev
Off topic but I wish Go had chosen to use fn rather than func
lionkor
I love the way Zig does allocators, when you compare it to Rust where allocation failures just panic (rolls eyes)
Jimiliyaa
[flagged]
ctxcode
These kind of tactics work for simple examples. In real world http servers you'll retain memory across requests (caches) and you'll need a way to handle blocking io. That's why most commonly we use GC'd/ownership languages for this + things like goroutines/tokio/etc.. web devs dont want to deal with memory themselfs.