#allocator #malloc #heap #kernel #no_std

no-std linked_list_allocator

Simple allocator usable for no_std systems. It builds a linked list from the freed blocks and thus needs no additional data structures.

37 releases

Uses old Rust 2015

0.8.11 Jan 2, 2021
0.8.10 Dec 28, 2020
0.8.6 Sep 24, 2020
0.8.4 May 3, 2020
0.1.2 Mar 5, 2016

#8 in Memory management

Download history 1695/week @ 2020-09-25 1229/week @ 2020-10-02 1592/week @ 2020-10-09 1062/week @ 2020-10-16 3334/week @ 2020-10-23 1591/week @ 2020-10-30 1416/week @ 2020-11-06 1815/week @ 2020-11-13 2314/week @ 2020-11-20 1870/week @ 2020-11-27 1850/week @ 2020-12-04 1369/week @ 2020-12-11 1646/week @ 2020-12-18 1511/week @ 2020-12-25 1719/week @ 2021-01-01 2162/week @ 2021-01-08

7,462 downloads per month
Used in 13 crates (8 directly)

Apache-2.0/MIT

35KB
627 lines

linked-list-allocator

Build Status

Documentation

Usage

Create a static allocator in your root module:

use linked_list_allocator::LockedHeap;

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

Before using this allocator, you need to init it:

pub fn init_heap() {
    let heap_start =;
    let heap_end =;
    let heap_size = heap_end - heap_start;
    unsafe {
        ALLOCATOR.lock().init(heap_start, heap_size);
    }
}

Features

  • use_spin (default): Provide a LockedHeap type that implements the GlobalAlloc trait by using a spinlock.
  • const_mut_refs (default): Makes the Heap::empty function const; requires nightly Rust.
  • use_spin_nightly (default): Makes the LockedHeap::empty function const, automatically enables use_spin and const_mut_refs; requires nightly Rust.
  • alloc_ref: Provide an implementation of the unstable AllocRef trait; requires nightly Rust.
    • Warning: The AllocRef trait is still regularly changed on the Rust side, so expect some regular breakage when using this feature.

License

This crate is dual-licensed under MIT or the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~32KB