Crates.io | emheap |
lib.rs | emheap |
version | |
source | src |
created_at | 2022-04-20 04:07:37.893599 |
updated_at | 2022-04-20 04:45:09.393 |
description | Tiny memory manager for embedded system. |
homepage | https://github.com/XiangYyang/emheap |
repository | https://github.com/XiangYyang/emheap |
max_upload_size | |
id | 570755 |
size | 0 |
The emheap
crate is a simple memory manager for embedded systems and microprocessors.
Here are the main features:
WARNING: DO NOT use this library on your PC.
In cargo.toml
[dependencies]
emheap = "0"
Then, in heap.c
, change the heap memory size:
#define HEAP_SIZE (4 * 1024)
Consider a Direct Computer Control System, it uses the ARM Cortex-M0+ microprocessor. Now, we want to use the alloc
crate.
At first, we should check out to the nightly channel:
rustup default nightly
Now, declare the alloc
crate in your codes:
#![feature(alloc_error_handler)]
extern crate alloc;
This crate is not dependent on unstable features, however, you need to use alloc_error_handler
to cause panic. Let's special the global allocator and the error handler:
use alloc::alloc::Layout;
use emheap::{heap, rsalloc::Allocator};
#[global_allocator]
pub static HEAP: Allocator = Allocator {};
#[alloc_error_handler]
fn alloc_error(_layout: Layout) -> ! {
// your code...
loop{}
}
Once all that is in place, now you can finally use the collections in alloc
:
use alloc::vec;
fn test() {
let arr = vec![1, 2, 3, 4, 5];
for i in arr {
do_other(i);
}
}