logoalt Hacker News

reallyreason • yesterday at 5:14 PM • 1 reply • view on HN

Not sure I understand what you're looking for exactly, but couldn't you just wrap a thread-local allocator (the design you're talking about) in a global allocator by referencing a static thread-local in that static global allocator? Then you wouldn't have to .new_in(), but you would still have thread-local allocation.

I'm not saying this is a good idea, just that it seems like Rust does maybe accommodate what you're talking about already.


Replies

atombender • yesterday at 5:34 PM

Sure, but that has the overhead of a thread-local variable, and requires using threads.

I guess where I'm getting as is that there are genuine use cases where you want to enforce an allocator throughout a subsystem without rewriting absolutely every line that can allocate. But Rust does not have any way to pass "implicit" context down the stack, from what I know.

With Zig, allocators are already explicit, but Rust didn't start out that way, and it doesn't really fit into how Rust code is written today.

➕ show 1 reply