r/ProgrammingLanguages • C3 - http://c3-lang.org • Feb 13 '26

Allocators from C to Zig

https://antonz.org/allocators/

This is an overview of allocator usage and availability in a few low level languages: Rust, Zig, Odin, C3, Hare and C.

I think it might be interesting to people designing standard libraries for their languages.

43 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/matthieum Feb 18 '26

I am still surprised by your first example. It’s considered “failed” if you don’t get the exact number of bytes requested? Or am I interpreting that wrong.

Well, whether it's failed or not is debatable.

Advantages of considering it failed include:

  1. Signalling that the block didn't change, therefore it can be used as is, no "post-shrink" operation need to run.
  2. Signalling that the block is still just as big as before, so you may as well keep the current capacity you've got (so as not to have to ask to grow back later).
  3. Signalling that the block is still just as big as before, so if you wished to free up some memory, nope.

It seems the only reason to consider it a success would be because that was the smallest block size you could possibly get for that request size anyway. But I may be missing some other reasons.