trallocator 0.2.2

A no_std lbrary for wrapping an existing allocator and tracking the heap usage.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented1 out of 8 items with examples
  • Size
  • Source code size: 10.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 899.18 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • xgroleau/trallocator
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • xgroleau

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.