slabmalloc Build Status Crates.io

Simple slab based malloc implementation in rust, in order to provide the necessary interface to rusts liballoc library. slabmalloc only relies on libcore and is designed to be used in kernel level code as the only interface a client needs to provide is the necessary mechanism to allocate and free 4KiB frames (or any other default page-size on non-x86 hardware).

Usage

```rust use slabmalloc::{SafeZoneAllocator};

[global_allocator]

static MEM_PROVIDER: SafeZoneAllocator = SafeZoneAllocator::new(&PAGER); ```

let mut mmap = MmapPageProvider::new(); let page = mmap.allocate_page();

let mut zone = ZoneAllocator::new(); let layout = Layout::fromsizealign(object_size, alignment).unwrap(); unsafe { zone.refill(layout, page.unwrap())? }; // Pre-load SCAllocator with memory

let allocated = zone.allocate(layout)?; zone.deallocate(allocated, layout)?; ```

let mut sa: SCAllocator = SCAllocator::new(object_size); unsafe { sa.refill(page.unwrap()); }

sa.allocate(layout)?; ```

Using on stable

By default this packages requires a nightly version of the Rust compiler. To be able to use this package with a stable version of the Rust compiler, default features have to be disabled, e.g. with slabmalloc = { version = ..., default_features = false }

Documentation

TODO