r/ProgrammingLanguages • u/Nuoji 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
View all comments
Show parent comment
1
u/matthieum Feb 14 '26
Imagine a ring-buffer of 16 elements, say
[0, 1, 2, ..., 14, 15]which contains only 5 elements (in the numbered slots). Since 5 << 16, we want to shrink it to 8 slots. But once we get to[0, 1, 2, ...]we've lost access to 14 and 15, so we cannot copy them.They're methods operating on allocated blocks.
Shrink in place doesn't allocate, instead, if possible, it splits the block in multiple pieces and make the (unused) pieces available for further allocations.
Grow in place may need to allocate more memory to grow the block.