1 unstable release
Uses new Rust 2024
| 0.1.0 | Jan 8, 2026 |
|---|
#364 in Memory management
18KB
368 lines
stable-block-arena
Block-allocated arena with stable handles that survive compaction
Features
- Stable handles: Removing elements doesn't invalidate handles to other elements
- Block-based storage: Memory is allocated/deallocated in fixed-size blocks instead of per-element
- Compaction: Reclaim memory from removed elements
- Zero-cost abstractions: Handles are just
u32wrappers
Use Cases
- Entity-component systems
- Graph data structures
- Resource managers
- Virtual machine object pools
- Any scenario requiring stable references with dynamic allocation
Example
use stable_block_arena::Arena;
let mut arena = Arena::new();
let hello = arena.insert("hello");
let world = arena.insert("world");
arena.remove(hello);
// Handle is still valid!
assert_eq!(arena.get(world), Some(&"world"));
// Reclaim memory blocks from removed elements
arena.compact(|_| true);
// Handle is still valid after compaction!
assert_eq!(arena.get(world), Some(&"world"));
// Remove 'world' during compaction
arena.compact(|handle| handle != world);
// World has been removed during compaction
assert_eq!(arena.get(world), None);
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.