[−][src]Crate compact_arena
A crate with a few single-typed arenas that work exclusively with indexes. The indexes are sized with the arena. This can reduce memory footprint when changing pointers to indices e.g. on 64-bit systems.
The arenas use "branded indices": The indices contain lifetimes that bind them to the arena so you cannot mix up two arenas by accident. See Gankro's thesis for more information about the concept and it's implementation in Rust.
Use the in_arena
and similar methods to run code within the scope of an
arena:
Examples
compact_arena::in_arena(|arena| { let idx = arena.add(1usize); assert_eq!(1, arena[idx]); });
You can use in_sized_arena
to change the initial size of the backing
memory:
compact_arena::in_sized_arena(1, |arena| { .. });
You can nest calls to work with multiple arenas:
compact_arena::in_sized_arena(1, |a| { compact_arena::in_sized_arena(1, |b| { .. }) });
The compiler will give you a scary lifetime error if you mix up arenas:
compact_arena::in_sized_arena(8, |a| { compact_arena::in_sized_arena(8, |b| { let i = a.add(1usize); b[i] } }
Structs
Idx | An index into the arena |
NanoArena | A "nano" arena containing 255 elements. This variant only works with
types implementing |
SmallArena | A "Small" arena based on a resizable slice (i.e. a |
TinyArena | A "tiny" arena containing <64K elements. This variant only works with
types implementing |
Functions
in_arena | Run code using an arena. The indirection through a |
in_nano_arena | Run code using a nano arena. The indirection through a |
in_sized_arena | Same as |
in_tiny_arena | Run code using a tiny arena. The indirection through a |
Type Definitions
Idx8 | The index type for a nano arena is 8 bits large |
Idx16 | The index type for a tiny arena is 16 bits large |
Idx32 | The index type for a small arena is 32 bits large |