Expand description
A dynamic external memory allocator implementing the functionality of a circular buffer.
The calling program is responsible for tracking which allocated part is
currently the frontmost/backmost region of a Ring
. When deallocating
a region, it must appropriately call dealloc_front
or dealloc_back
depending on the position of the region within a Ring
.
Examples
use xalloc::{Ring, RingRegion};
let mut ring: Ring<u32> = Ring::new(10);
// Allocate regions
// [ ]
let alloc1: (RingRegion<u32>, u32) = ring.alloc_back(4).unwrap();
// [[ 1 ] ]
let alloc2: (RingRegion<u32>, u32) = ring.alloc_back(4).unwrap();
// [[ 1 ][ 2 ] ]
let (region1, offset1) = alloc1;
let (region2, offset2) = alloc2;
println!("allocated #1: {:?}", (®ion1, offset1));
println!("allocated #2: {:?}", (®ion2, offset2));
// Deallocate regions
// [[ 1 ][ 2 ] ]
ring.dealloc_front(region1);
// [ [ 2 ] ]
ring.dealloc_front(region2);
// [ ]
Structs
A dynamic external memory allocator providing the functionality of a
circular buffer.
A handle type to a region allocated in a
Ring
.