|0.1.1||Jul 12, 2023|
|0.1.0||Jul 4, 2023|
#142 in Memory management
25 downloads per month
Used in btree-plus-store
rustc-arena-modified: rustc-arena ported to stable rust with additional features
Forked from rustc_arena
Why would you want this?
- Allocating objects in an arena can be faster then regular allocation
- An arena doubles as a collection where you can insert objects behind a shared reference. Instead of
Cloneing objects and possibly using
Rcs, use an
Arenaand copy the references.
rustc_arena_modified::TypedArenaallows coalescing and clearing objects behind a mutable reference, while saving the chunks so they don't need to be re-allocated. This is equivalent to calling
into_vecand then converting the vector back into an arena, but faster, because you don't need to allocate anything.
rustc_arena_modified::TypedArenais also significantly faster at iteration according to the benchmarks (other differences are negligible; see benchmarks)
rustc_arena_modified::TypedArenareturns a shared reference to allocated values, so it can iterate values behind a shared reference like
typed-arena-nomut, it can also be no-op converted between
rustc_arena_modified::TypedArenaMut, which is the same but returns mutable references. And, you can get iterate mutable element references behind a mutable reference to even the shared arena, because that ensures there are no active shared references.
SlabArena, a wrapper for
rustc_arena_modified::TypedArenawhich makes it keep track of freed elements in a linked list so their memory can be reclaimed. This comes with some drawbacks, like the inability to allocate slices in the free list (???: allow slice allocation, just make it not part of the free list?)
- TODO: Comparisons between
Bumpis objectively better)
What is it?
A port of
rustc_arena into stable rust with the following new features:
TypedArena::iterto iterate over all objects in the arena
TypedArena::clearto coalesce clearing objects behind a mutable reference, while saving the chunks so they don't need to be re-allocated.
This library makes heavy use of
unsafe and isn't fully tested with MIRI. There are tests for most operations and edge cases, and the base functionality is copied almost verbatim from
rustc_arena which is very well-tested. But the extra functionality is much less tested, and especially with the heavy use of
unsafe, it shouldn't be used in production.
Overall, performs around the same speed as
typed_arena, except iteration is significantly faster than
slab_arena performs noticeably slower.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.