#heap-allocator #heap #allocator #no-std

no-std trallocator

A no_std lbrary for wrapping an existing allocator and tracking the heap usage

3 unstable releases

0.2.1 Nov 8, 2023
0.2.0 Mar 22, 2023
0.1.0 Mar 14, 2023

#313 in Embedded development

Download history 5/week @ 2024-01-08 21/week @ 2024-01-15 31/week @ 2024-02-12 38/week @ 2024-02-19 33/week @ 2024-02-26 20/week @ 2024-03-11 15/week @ 2024-03-18 33/week @ 2024-03-25 67/week @ 2024-04-01 22/week @ 2024-04-08 23/week @ 2024-04-15 29/week @ 2024-04-22

142 downloads per month
Used in lorawan

MIT/Apache

8KB
97 lines

Trallocator

crates.io documentation

A simple no_std library for wrapping an existing allocator and tracking the heap usage. Main usage is to keep track of the heap usage on embedded systems

Usage

Simply wrap an existing allocator with a Trallocator.

Examples

With another allocator, here we use the system one

extern crate alloc;
extern crate std;
use alloc::vec::Vec;
use std::alloc::System;

use trallocator::Trallocator;

#[global_allocator]
static ALLOCATOR: Trallocator<System> = Trallocator::new(System);
fn main() {
    let init = ALLOCATOR.usage();
    let mut vec: Vec<u8> = Vec::new();
    vec.reserve_exact(32);
    assert_eq!(ALLOCATOR.usage(), init+32);
}

With the allocator API

#![feature(allocator_api)]
extern crate alloc;
extern crate std;
use alloc::vec::Vec;
use std::alloc::System;

use trallocator::Trallocator;

let tralloc: Trallocator<System> = Trallocator::new(System);
assert_eq!(tralloc.usage(), 0);
let mut vec: Vec<u8, _> = Vec::new_in(&tralloc);
vec.reserve_exact(32);
assert_eq!(tralloc.usage(), 32);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features