2 unstable releases
new 0.2.0 | May 24, 2025 |
---|---|
0.1.0 | May 24, 2025 |
#275 in Memory management
13KB
163 lines
stack-arena
A fast, stack-like arena allocator inspired by GNU obstack, implemented in Rust.
Features
- Efficient allocation of variable-sized objects with minimal overhead.
- Objects are allocated in contiguous memory chunks.
- Stack-like (LIFO) allocation and deallocation.
- No per-object deallocation: free all objects at once or roll back to a checkpoint.
- Suitable for parsers, interpreters, and other high-performance scenarios.
Usage
Add to your Cargo.toml
:
[dependencies]
stack-arena = "0.1"
Example:
use stack_arena::SimpleObstack;
fn main() {
let mut ob = SimpleObstack::<1024, u8>::new();
ob.grow(b"hello");
let ptr = ob.finish();
// Use ptr...
}
Safety
- All returned pointers or references are valid as long as the arena is not cleared or reset.
- Objects are always stored contiguously in a single chunk.
License
MIT
Acknowledgements
Inspired by GNU obstack.