Skip to main content

Crate subms_arena_allocator

Crate subms_arena_allocator 

Source
Expand description

Fixed-capacity bump-pointer arena. Allocate fixed-layout values into a single pre-sized byte buffer; reset() rewinds the bump cursor so the next request can reuse the entire arena.

Drop is NOT run on items in the arena. Anything with a non-trivial Drop (e.g. String, Vec) will leak its heap allocation if you store it in this arena. Bump::alloc_copy is constrained to Copy types as the safe public surface.

Base is single-chunk and fixed-capacity. When the chunk is exhausted alloc_* panics and try_alloc_* returns None. Opt into the growable feature for the auto-grow variant.

Thread safety: none, by construction. The crate declares no unsafe impl Send / Sync. The raw-pointer arenas (Bump, GrowableBump, AlignedBump) are therefore neither Send nor Sync; TypedArena<T> owns plain Vec storage so it inherits T’s auto traits, and every mutating method takes &mut self, so a shared reference cannot allocate. Give each thread its own arena rather than reaching for a lock - a shared cursor is a contended cache line, which is the cost this structure exists to avoid.

use subms_arena_allocator::Bump;
let mut a = Bump::with_capacity(1024);
let x: &mut u32 = a.alloc_copy(42u32);
assert_eq!(*x, 42);
a.reset();

Full writeup, design notes and measured benchmarks: https://www.submillisecond.com/cookbook/recipes/subms-arena-allocator

Re-exports§

pub use features::aligned::AlignedBump;
pub use features::growable::GrowableBump;
pub use features::stats::BumpStats;
pub use features::stats::StatsBump;
pub use features::typed::Slot;
pub use features::typed::TypedArena;

Modules§

features
Opt-in feature catalog. Each submodule is gated by its own Cargo feature flag and adds a specific capability to the base bump arena without bloating the core build.
recipe
SubMsRecipe impl. Behind the harness feature (which implies growable).

Structs§

Bump
Fixed-capacity bump-pointer arena.