3 ms·
Not deeply familiar with Rust but with its memory management concept does it allow for something like arena allocator?
by FpUser 6y ago
Not deeply familiar with Rust but with its memory management concept does it allow for something like arena allocator?
- ibraheemdev 6y agoYup: https://docs.rs/typed_arena https://docs.rs/typed_arena
- whateveracct 6y agoThat just has allocation, but no way to reset the arena & reclaim its memory. But then again, you'd have to make it so no allocations from the arena are alive & in use when you reset the arena. Definitely a downside :/ On a side-note: I'm fairly sure the ST trick + -XLinearTypes will allow a better & still type-safe arena allocator to be written in Haskell than is currently possible in Rust.
- gpm 6y ago> but no way to reset the arena & reclaim its memory. But then again, you'd have to make it so no allocations from the arena are alive & in use when you reset the arena Looks like that implementation doesn't, but the borrow checker can definitely specify that sort of constraint (it looks `fn foo(self) -> Self`). I think it's not exposed because the code assumes that all but the last chunk are completely filled - but it could also just be that no one asked for that.
- pornel 6y agoBorrows are scope based, so if you limit arena usage to a scope (e.g. inside your frame loop), then it should be fairly trivial to reset it. Reclaiming should theoretically be possible too via a method that takes ownership of the arena (the borrow checker prevents moves while an object is borrowed).
- whateveracct 6y agohm interesting - so basically, the blocks you borrow from the arena can be scoped to be <= the scope of the arena itself, which will then make them respect a reset?
- the_duke 6y agoYes, but for now only if you use custom data structures. Custom allocator support for the std types (Vec, HashMap, etc) is coming, but at a snails pace.