2 ms·
> The most flexible design Not quite. For the most general case, you probably want allocator to be a proper parameter instead of a type parameter. For exampl
by throwawaymaths 4y ago
> The most flexible design
Not quite. For the most general case, you probably want allocator to be a proper parameter instead of a type parameter. For example, suppose you have a green thread that you want to have its own isolated heap. Then you can't assume that any given allocator is a singleton in its type; The struct itself must somehow be able to find to its "owner" on release. In the green thread case you can't "just use threadlocal" because a green thread might not be sticky to an os thread.
- twic 4y agoRust already has almost exactly this problem with keeping track of the current task in the async framework. As far as I know, the solution is indeed to use a thread local, and be scrupulous about updating it on task entry. It's ugly but it seems to work.
- cormacrelf 4y agoThey thought of that. There are Box::new_in variants for all the other ways of creating a Box. You can put data in there to identify a green thread’s heap. https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.new_in https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#m...