#allocation #bound #limit #memory #allocator

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

1 unstable release

0.1.0 Oct 21, 2019

#6 in #bound

Download history 600/week @ 2022-04-22 244/week @ 2022-04-29 444/week @ 2022-05-06 424/week @ 2022-05-13 176/week @ 2022-05-20 162/week @ 2022-05-27 170/week @ 2022-06-03 313/week @ 2022-06-10 245/week @ 2022-06-17 224/week @ 2022-06-24 292/week @ 2022-07-01 162/week @ 2022-07-08 328/week @ 2022-07-15 248/week @ 2022-07-22 151/week @ 2022-07-29 280/week @ 2022-08-05

1,046 downloads per month
Used in crates-index

MIT/Apache

14KB
328 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

  • nightly