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
I'm not sure what you mean exactly, so let's give an example :)
Let's imagine that the store has, so far, allocated 3 blocks A, B, and C, and the user requests to deallocate B. The blocks A & C are still valid, and may be referenced separately, while B is being deallocated, thus the implementer of the store must make sure that no (indirect) reference to A & C exist throughout the deallocation of B.
For example, using a
LinkedList<Block>to implementStoreMultiplewould be invalid, as taking a&mutto theLinkedListinstance indirectly takes a&mutto every single node.In the vast majority of cases, yes. You will either need interior mutability or
*mutto implementStoreMultiplesoundly.Note that implementing
StoreMultiplefor&MyStoreis not enough. IfMyStoreis held be value in the collection, then taking a&mutto the collection indirectly means taking a&muttoMyStore, and therefore its implementation must have some kind of "firewall" to prevent this propagation to the blocks.This requirement for firewall is, in fact, the very reason for the existence of
StoreSingle, which does not require one.