A fast (but limited) allocation arena for values of a single type.
Allocated objects are destroyed all at once, when the arena itself is destroyed. There is no deallocation of individual objects while the arena itself is still alive. The flipside is that allocation is fast: typically just a vector push.
There is also a method
into_vec() to recover ownership of allocated objects
when the arena is no longer required, instead of destroying everything.
use Arena; let monsters = new; let goku = monsters.alloc; assert!;
All allocated objects get the same lifetime, so you can safely create cycles between them. This can be useful for certain data structures, such as graphs and trees with parent pointers.
use Cell; use Arena; let arena = new; let a = arena.alloc; let b = arena.alloc; a.other.set; b.other.set;
Need to allocate many different types of values?
Use multiple arenas if you have only a couple different types or try
bumpalo, which is a bump-allocation arena
can allocate heterogenous types of values.
Want allocation to return identifiers instead of references and dealing with references and lifetimes everywhere?
Need to deallocate individual objects at a time?
for an arena-style crate or look for a more traditional allocator.