A simple slab allocator that manages fixed-size objects in pages. It's designed for no_std environments where you need efficient memory allocation without the standard library.
The allocator:
- Organizes memory into 4KB pages
- Maintains a free list for quick allocation/deallocation
- Automatically handles alignment requirements
- Reuses freed memory efficiently
Linux - x86_64
cargo run --target x86_64-unknown-linux-gnuLinux - aarch64
cargo run --target aarch64-unknown-linux-gnuuse slab_allocator::SlabAllocator;
use core::ptr::NonNull;
let mut allocator = SlabAllocator::new(64); // Allocate objects of size 64 bytes
// Allocate an object
if let Some(ptr) = allocator.alloc() {
// Use the memory...
// Free it when done
allocator.free(ptr);
}Run the test suite:
cargo test