#bound #allocation #memory #limit #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

2 releases

0.1.1 Aug 15, 2022
0.1.0 Oct 21, 2019

#64 in Memory management

Download history 358/week @ 2022-08-07 370/week @ 2022-08-14 407/week @ 2022-08-21 345/week @ 2022-08-28 329/week @ 2022-09-04 319/week @ 2022-09-11 350/week @ 2022-09-18 302/week @ 2022-09-25 354/week @ 2022-10-02 358/week @ 2022-10-09 299/week @ 2022-10-16 318/week @ 2022-10-23 279/week @ 2022-10-30 426/week @ 2022-11-06 288/week @ 2022-11-13 198/week @ 2022-11-20

1,205 downloads per month
Used in crates-index

MIT/Apache

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