#memory-allocator #limit #tracking #track #another #wraps #set

cap

An allocator that can track and limit memory usage. This crate provides a generic allocator that wraps another allocator, tracking memory usage and enabling limits to be set

3 releases

0.1.2 Mar 26, 2023
0.1.1 Aug 15, 2022
0.1.0 Oct 21, 2019

#114 in Memory management

Download history 806/week @ 2023-12-11 832/week @ 2023-12-18 431/week @ 2023-12-25 1136/week @ 2024-01-01 1432/week @ 2024-01-08 1309/week @ 2024-01-15 1700/week @ 2024-01-22 2046/week @ 2024-01-29 2303/week @ 2024-02-05 2334/week @ 2024-02-12 1768/week @ 2024-02-19 1957/week @ 2024-02-26 1908/week @ 2024-03-04 2294/week @ 2024-03-11 2144/week @ 2024-03-18 1992/week @ 2024-03-25

8,466 downloads per month
Used in 3 crates

MIT/Apache

17KB
413 lines

cap

Crates.io MIT / Apache 2.0 licensed Build Status

Docs

An allocator that can track and limit memory usage.

This crate provides a generic allocator that wraps another allocator, tracking memory usage and enabling limits to be set.

Example

It can be used by declaring a static and marking it with the #[global_allocator] attribute:

use std::alloc;
use cap::Cap;

#[global_allocator]
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::max_value());

fn main() {
    // Set the limit to 30MiB.
    ALLOCATOR.set_limit(30 * 1024 * 1024).unwrap();
    // ...
    println!("Currently allocated: {}B", ALLOCATOR.allocated());
}

License

Licensed under either of

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.

No runtime deps

Features