bump-local

Crates.iobump-local
lib.rsbump-local
version0.1.0
created_at2026-01-18 20:26:12.563174+00
updated_at2026-01-18 20:26:12.563174+00
descriptionA thread-safe bump allocator backed by bumpalo crate.
homepage
repositoryhttps://github.com/rstrait/bump-local
max_upload_size
id2053028
size41,171
Alex (alextsugi)

documentation

https://docs.rs/bump-local

README

bump-local

A Sync + Send allocator wrapper around bumpalo using per-thread bump allocators.

Why?

bumpalo::Bump is fast but not thread-safe. This crate provides a thread-safe interface by giving each thread its own Bump instance via thread-local storage, combining bumpalo's allocation speed with Sync + Send semantics.

This crate is useful when you need to pass a custom allocator to a library that requires Sync + Send. If you're writing multithreaded code from scratch, consider creating per-thread allocators upfront and using them instead.

Usage

use bump_local::Bump;

let mut bump = Bump::new();
let bump_clone = bump.clone();
let handle = std::thread::spawn(move || {
    // This thread gets its own bump allocator instance
    let local = bump_clone.local();
    local.as_inner().alloc(42);
    // bump_clone is dropped when thread finishes
});

// Wait for thread to finish
handle.join().unwrap();

// Now safe to reset - all clones are dropped
bump.reset_all().unwrap();

Check out the examples directory for examples using rayon and bumpalo collections.

Limitations

Resetting all allocators requires exclusive access to the Bump.

This library is designed for the fork-join model, where you allocate during parallel work and reset between phases.

Future versions may add a generation-based resetting option to avoid the exclusive access requirement.

Minimum Supported Rust Version (MSRV)

This crate requires Rust 1.71.1 or later.

License

MIT OR Apache-2.0

Commit count: 8

cargo fmt