Crates.io | compact_arena |
lib.rs | compact_arena |
version | 0.5.0 |
source | src |
created_at | 2019-03-22 12:13:44.937436 |
updated_at | 2024-08-26 20:12:09.537587 |
description | A crate with some types to allow indexed arenas with small memory footprint |
homepage | |
repository | https://github.com/llogiq/compact_arena |
max_upload_size | |
id | 123106 |
size | 46,738 |
This is a crate with arenas that work with indices. Currently there are three
types: SmallArena
uses 32-bit indices and can hold up to 2³² objects.
TinyArena
uses 16-bit indices and can hold up to 65536 objects (only 16384
on windows), regardless of object size. NanoArena
uses 8-bit indices and
contain up to 256 objects.
This can conserve memory in scenarios where we have a large-ish number of
relations between objects, e.g. in graph algorithms. NanoArena
is likely
most useful in embedded scenarios.
Add the following dependency to your Cargo.toml
compact_arena = "0.5"
By default, the TinyArena
uses no unsafe code to maintain storage, but
requires the stored types to be Default + Copy
. To change this, you can use
the uninit
feature to enable usage on all types with a bit more unsafe code:
compact_arena = { version = "0.5", features = ["alloc", "uninit"] }
In your code, use it as follows:
use compact_arena::mk_arena;
mk_arena!(arena);
let hello = arena.add("Hello");
let world = arena.add("World");
println!("{}, {}!", arena[hello], arena[world]);
For further information, please read the documentation.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.