#arena #no-heap #no-std

no-std compact_arena

A crate with some types to allow indexed arenas with small memory footprint

2 releases

0.4.1 Oct 18, 2020
0.4.0 Jul 14, 2019
0.3.2 May 27, 2019
0.3.0 Apr 25, 2019
0.1.1 Mar 26, 2019

#241 in Memory management

Download history 4/week @ 2024-02-15 31/week @ 2024-02-22 32/week @ 2024-02-29 7/week @ 2024-03-07 7/week @ 2024-03-14 4/week @ 2024-03-21

56 downloads per month

MIT/Apache

25KB
307 lines

compact_arena

Travis Build Status Docs Current Crates.io Version

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, 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.

Usage:

Add the following dependency to your Cargo.toml

compact_arena = "0.3"

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.3", 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.

License

Licensed under either of

at your option.

Contribution

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.

No runtime deps