| Crates.io | o1heap |
| lib.rs | o1heap |
| version | 0.0.2 |
| created_at | 2025-11-25 20:12:48.623698+00 |
| updated_at | 2025-11-27 00:02:40.499455+00 |
| description | Rust bindings for o1heap - a constant-time deterministic memory allocator |
| homepage | |
| repository | https://github.com/laktoosivaba/o1heap-rs |
| max_upload_size | |
| id | 1950392 |
| size | 1,029,026 |
Rust bindings for o1heap - a constant-time deterministic memory allocator for hard real-time systems.
[dependencies]
o1heap = "0.0.2"
#![no_std]
#![no_main]
extern crate alloc;
use alloc::vec::Vec;
use core::mem::{size_of, MaybeUninit};
use core::ptr::addr_of_mut;
use cortex_m_rt::entry;
use o1heap::O1Heap;
use panic_halt as _;
#[repr(C, align(16))]
struct Arena([MaybeUninit<u8>; 8192]);
static mut ARENA: Arena = Arena([MaybeUninit::uninit(); 8192]);
#[global_allocator]
static HEAP: O1Heap = O1Heap::empty();
#[entry]
fn main() -> ! {
unsafe {
HEAP.init(addr_of_mut!(ARENA).cast(), size_of::<Arena>())
.expect("heap init failed");
}
let mut xs = Vec::new();
xs.push(1);
loop { }
}
o1heap guarantees that all allocated memory is aligned to:
This alignment is available as o1heap::ALIGNMENT.
let diag = heap.diagnostics();
println!("Capacity: {}", diag.capacity);
println!("Allocated: {}", diag.allocated);
println!("Peak allocated: {}", diag.peak_allocated);
println!("OOM count: {}", diag.oom_count);
assert!(heap.invariants_hold());
o1heap is not thread-safe. If you need to use it from multiple threads or interrupt contexts, you must provide external synchronization (e.g., critical sections, mutexes).
MIT license. The underlying o1heap C library is also MIT licensed.