Skip to content

Latest commit

 

History

History
65 lines (41 loc) · 1.24 KB

File metadata and controls

65 lines (41 loc) · 1.24 KB

slab allocator

A minimal slab allocator in rust no_std

License: GPL v3 Rust



📖 About

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

💻 Installation

Linux - x86_64

cargo run --target x86_64-unknown-linux-gnu

Linux - aarch64

cargo run --target aarch64-unknown-linux-gnu

🚀 Usage

use 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);
}

🧪 Testing

Run the test suite:

cargo test