4 releases (2 breaking)

0.3.1 May 11, 2021
0.3.0 Dec 27, 2019
0.2.0 Dec 26, 2019
0.1.0 Dec 25, 2019

#286 in Memory management

22 downloads per month

MIT/Apache

24KB
301 lines

Kioku

A growable memory arena for Copy types.

This arena works by internally allocating memory in large-ish blocks of memory one-at-a-time, and doling out memory from the current block in linear order until its space runs out.

Additionally, it attempts to minimize wasted space through some heuristics, and has special handling for larger-than-block-size allocation requests.

Some contrived example usage:

let arena = Arena::new().with_block_size(1024);

let integer = arena.alloc(42);
let array1 = arena.copy_slice(&[1, 2, 3, 4, 5, 42]);
assert_eq!(*integer, array1[5]);

*integer = 16;
array1[1] = 16;
assert_eq!(*integer, array1[1]);

let character = arena.alloc('A');
let array2 = arena.alloc_array('A', 42);
assert_eq!(array2.len(), 42);
assert_eq!(*character, array2[20]);

*character = '';
array2[30] = '';
assert_eq!(*character, array2[30]);

Other features include:

  • Allocating with specific memory alignment.
  • Allocating strings.
  • Configurable growth strategies.

License

This project is licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Kioku by you will be licensed as above, without any additional terms or conditions.

No runtime deps