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

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

#120 in Memory management

Download history 1275/week @ 2024-01-02 1402/week @ 2024-01-09 1410/week @ 2024-01-16 1600/week @ 2024-01-23 2086/week @ 2024-01-30 2348/week @ 2024-02-06 2292/week @ 2024-02-13 2032/week @ 2024-02-20 1694/week @ 2024-02-27 1879/week @ 2024-03-05 2424/week @ 2024-03-12 2283/week @ 2024-03-19 1757/week @ 2024-03-26 2216/week @ 2024-04-02 2388/week @ 2024-04-09 2094/week @ 2024-04-16

8,973 downloads per month
Used in 4 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