#allocator #no-std #heap

no-std buddy_system_allocator

A bare metal allocator that uses buddy system

19 unstable releases (6 breaking)

0.7.0 Feb 6, 2021
0.6.0 Nov 23, 2020
0.5.0 Oct 1, 2020
0.4.0 Apr 19, 2020
0.1.2 Mar 18, 2019

#33 in Memory management

Download history 50/week @ 2020-11-13 108/week @ 2020-11-20 108/week @ 2020-11-27 104/week @ 2020-12-04 80/week @ 2020-12-11 58/week @ 2020-12-18 45/week @ 2020-12-25 141/week @ 2021-01-01 95/week @ 2021-01-08 72/week @ 2021-01-15 173/week @ 2021-01-22 200/week @ 2021-01-29 110/week @ 2021-02-05 152/week @ 2021-02-12 107/week @ 2021-02-19 223/week @ 2021-02-26

447 downloads per month

MIT license

25KB
556 lines

buddy_system_allocator

Crates.io version docs.rs

An (almost) drop-in replacement for phil-opp/linked-list-allocator. But it uses buddy system instead.

Usage

To use buddy_system_allocator for global allocator:

use buddy_system_allocator::LockedHeap;

#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();

To init the allocator:

unsafe {
    HEAP_ALLOCATOR.lock().init(heap_start, heap_size);
    // or
    HEAP_ALLOCATOR.lock().add_to_heap(heap_start, heap_end);
}

You can also use FrameAllocator and LockedHeapWithRescue, see their documentation for usage.

Features

  • use_spin (default): Provide a LockedHeap type that implements the GlobalAlloc trait by using a spinlock.
  • const_fn (nightly only): Provide const fn version of LockedHeapWithRescue::new.

License

Some code comes from phil-opp's linked-list-allocator.

Licensed under MIT License. Thanks phill-opp's linked-list-allocator for inspirations and interface.

Dependencies

~25KB