allocal

Crates.ioallocal
lib.rsallocal
version0.1.1
sourcesrc
created_at2020-12-21 19:31:06.810099
updated_at2020-12-21 20:06:23.273044
descriptionA simple crate that allows storing objects of different types into a single region.
homepage
repositoryhttps://github.com/gymore-z/allocal
max_upload_size
id325367
size11,738
Gymore (gymore-z)

documentation

https://docs.rs/allocal

README

allocal is a simple crate that provides the Allocal structure. This structure works a bit like an allocator but only works on a fixed continuous region of the memory of the heap.

Example

use allocal::Allocal;

// Create a 1024 bytes-long region to store any kind of data
let mut region = Allocal::with_capacity(1024);

// Allocate things into the buffer
// an error is returned if the region is full
let location_i32 = region.allocate(123i32).unwrap();
let location_i64 = region.allocate(123i64).unwrap();
let location_vec = region.allocate(vec![1u8, 2, 3]).unwrap();

// You can then get back references to your items
*region.get_mut(location_i32) = 124;
region.get_mut(location_vec).push(4);

assert_eq!(region.get(location_i64), &123);

// Or deallocate them when you don't needs them anymore to get some space
let vec: Vec<u8> = region.deallocate(location_vec);

assert_eq!(vec.len(), 4);
Commit count: 0

cargo fmt