[][src]Crate ruyi_slab

Provides an object based allocator Slab<T> backed by a contiguous growable array of slots.

The slab allocator pre-allocates memory for objects of same type so that it reduces fragmentation caused by allocations and deallocations. When allocating memory for an object, it just finds a free (unused) slot, marks it as used, and returns the index of the slot for later access to the object. When freeing an object, it just adds the slot holding the object to the list of free (unused) slots after dropping the object.

Examples

// Explicitly create a Slab<T> with new
let mut slab = Slab::new();

// Insert an object into the slab
let one = slab.insert(1);

// Remove an object at the specified index
let removed = slab.remove(one);

assert_eq!(removed.unwrap(), 1);

Structs

Entry

A handle to a free slot in a Slab<T>.

Slab

An object based allocator backed by a contiguous growable array of slots.