#allocator #memory-usage #peak-memory

peak_alloc

An allocator to keep track of (the max) allocated memory

3 unstable releases

0.2.1 Feb 26, 2024
0.2.0 Apr 5, 2023
0.1.0 Jan 8, 2021

#65 in Memory management

Download history 1068/week @ 2024-02-26 840/week @ 2024-03-04 729/week @ 2024-03-11 869/week @ 2024-03-18 833/week @ 2024-03-25 983/week @ 2024-04-01 899/week @ 2024-04-08 887/week @ 2024-04-15 750/week @ 2024-04-22 1036/week @ 2024-04-29 870/week @ 2024-05-06 693/week @ 2024-05-13 700/week @ 2024-05-20 523/week @ 2024-05-27 981/week @ 2024-06-03 898/week @ 2024-06-10

3,141 downloads per month
Used in 11 crates (10 directly)

MIT license

11KB
84 lines

Peak Alloc

Peak Alloc is a dead simple and willingly low overhead allocator for rust which allows you to track (and consult) the amount of memory that is being allocated to your process as well as the maximum amount of memory that has been allocatd to your process over the course of its life.

Note 1:

When I mean that peak alloc is low overhead, I mean that all it ever maintains, is a pair of two atomic usize. So the overhead is low...but there is and overhead because of the atomic number manipulations.

Note 2:

The peak allocator is really just a shim around the system allocator. The bulk of its work is delegated to the system allocator and all PeakAlloc does is to maintain the atomic counters.

Usage

In your Cargo.toml, you should add the following line to your dependencies section.

[dependencies]
peak_alloc = "0.2.0"

Then in your main code, you will simply use it as shown below:

use peak_alloc::PeakAlloc;

#[global_allocator]
static PEAK_ALLOC: PeakAlloc = PeakAlloc;

fn main() {
	// Do your funky stuff...

	let current_mem = PEAK_ALLOC.current_usage_as_mb();
	println!("This program currently uses {} MB of RAM.", current_mem);
	let peak_mem = PEAK_ALLOC.peak_usage_as_gb();
	println!("The max amount that was used {}", peak_mem);
}

No runtime deps