Crates.io | trallocator |
lib.rs | trallocator |
version | 0.2.1 |
source | src |
created_at | 2023-03-14 19:21:06.605788 |
updated_at | 2023-11-08 20:52:13.865583 |
description | A no_std lbrary for wrapping an existing allocator and tracking the heap usage. |
homepage | https://github.com/xgroleau/trallocator |
repository | https://github.com/xgroleau/trallocator |
max_upload_size | |
id | 810088 |
size | 10,103 |
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
Simply wrap an existing allocator with a Trallocator
.
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);
Licensed under either of
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.