#allocator #limit #memory #cap

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
Download history 11/week @ 2020-12-24 34/week @ 2020-12-31 96/week @ 2021-01-07 52/week @ 2021-01-14 42/week @ 2021-01-21 115/week @ 2021-01-28 125/week @ 2021-02-04 97/week @ 2021-02-11 45/week @ 2021-02-18 34/week @ 2021-02-25 56/week @ 2021-03-04 13/week @ 2021-03-11 265/week @ 2021-03-18 237/week @ 2021-03-25 221/week @ 2021-04-01 197/week @ 2021-04-08

237 downloads per month

MIT/Apache

13KB
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