peakmem_alloc
An instrumenting middleware for global allocators in Rust, useful to find the peak memory consumed by a function.
Example
use peakmem_alloc::*;
use std::alloc::System;
#[global_allocator]
static GLOBAL: &PeakMemAlloc<System> = &INSTRUMENTED_SYSTEM;
#[test]
fn example_using_region() {
GLOBAL.reset_peak_memory(); let _x: Vec<u8> = Vec::with_capacity(1_024);
println!(
"Peak Memory used by function : {:#?}",
GLOBAL.get_peak_memory()
);
}
Custom allocators
You can wrap your existing allocator as follows:
use jemallocator::Jemalloc;
use peakmem_alloc::*;
#[global_allocator]
static GLOBAL: PeakMemAlloc<Jemalloc> = PeakMemAlloc::new(Jemalloc);