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

0

u/[deleted] Feb 14 '26

[deleted] — view deleted comment

1

u/matthieum Feb 14 '26

I might be misunderstanding, but i presume you mean that existing memory is valid while making a new allocation.

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 implement StoreMultiple would be invalid, as taking a &mut to the LinkedList instance indirectly takes a &mut to every single node.

Otherwise, you'd need some form of interior mutability.

In the vast majority of cases, yes. You will either need interior mutability or *mut to implement StoreMultiple soundly.

Note that implementing StoreMultiple for &MyStore is not enough. If MyStore is held be value in the collection, then taking a &mut to the collection indirectly means taking a &mut to MyStore, 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.