| Crates.io | bump-local |
| lib.rs | bump-local |
| version | 0.1.0 |
| created_at | 2026-01-18 20:26:12.563174+00 |
| updated_at | 2026-01-18 20:26:12.563174+00 |
| description | A thread-safe bump allocator backed by bumpalo crate. |
| homepage | |
| repository | https://github.com/rstrait/bump-local |
| max_upload_size | |
| id | 2053028 |
| size | 41,171 |
bump-localA Sync + Send allocator wrapper around bumpalo using per-thread bump allocators.
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.
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.
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.
This crate requires Rust 1.71.1 or later.
MIT OR Apache-2.0