|0.3.3||Sep 18, 2023|
|0.3.2||Dec 20, 2022|
|0.2.3||Nov 11, 2022|
#203 in Memory management
40 downloads per month
An arena that allocates values of a single type (similar to typed-arena) using chunks of memory that have a configurable fixed size. This enables it to perform allocations in non-amortized O(1) (constant) time.
Other arena implementations, like typed-arena, are optimized for throughput: they allocate chunks of memory with exponentially increasing sizes, which results in amortized constant-time allocations.
fixed-typed-arena is optimized for latency: it allocates chunks of memory with a fixed, configurable size, and individual value allocations are performed in non-amortized constant time.
use fixed_typed_arena::Arena; struct Item(u64); let arena = Arena::<_, 128>::new(); let item1 = arena.alloc(Item(1)); let item2 = arena.alloc(Item(2)); item1.0 += item2.0; assert_eq!(item1.0, 3); assert_eq!(item2.0, 2);
Items allocated by an
Arena can contain references with the same life
as the arena itself, including references to other items, but the crate
dropck_eyepatch must be enabled. This requires Rust nightly, as
fixed-typed-arena must use the eponymous unstable language feature.
Alternatively, you may be able to use a
This crate also provides
ManuallyDropArena, which is like
returns references of any lifetime, including
'static. The advantage of
this type is that it can be used without being borrowed, but it comes with
the tradeoff that it will leak memory unless the unsafe
drop method is
fixed-typed-arena’s arena types allow iteration over all allocated items.
Safe mutable iteration is provided for
Arena, and safe immutable
iteration is provided for all arena types if
Options::Mutable is false.
Unsafe mutable and immutable iteration is provided for all arena types
regardless of options.