Crate alloc_cortex_m [] [src]

A heap allocator for Cortex-M processors

Example

// Plug in the allocator crate
extern crate alloc_cortex_m;
extern crate collections;

use collections::Vec;
use alloc_cortex_m::CortexMHeap;

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

// These symbols come from a linker script
extern "C" {
    static mut _heap_start: usize;
    static mut _heap_end: usize;
}

#[no_mangle]
pub fn main() -> ! {
    // Initialize the heap BEFORE you use the allocator
    unsafe { ALLOCATOR.init(_heap_start, _heap_end - _heap_start) }

    let mut xs = Vec::new();
    xs.push(1);
    // ...
}

And in your linker script, you might have something like:

/* space reserved for the stack */
_stack_size = 0x1000;

/* `.` is right after the .bss and .data sections */
_heap_start = .;
_heap_end = ORIGIN(SRAM) + LENGTH(SRAM) - _stack_size;

Structs

CortexMHeap