limit-alloc

Crates.iolimit-alloc
lib.rslimit-alloc
version0.1.0
sourcesrc
created_at2022-07-09 13:28:40.260865
updated_at2022-07-09 13:28:40.260865
descriptionA custom allocator that allows to limit the available memory
homepage
repositoryhttps://github.com/Badel2/limit-alloc
max_upload_size
id622530
size42,934
(Badel2)

documentation

README

limit-alloc

A custom allocator that allows to limit the available memory.

Usage

use limit_alloc::Limit;
use std::alloc::System;

// Limit available RAM to 4MB
#[global_allocator]
static A: Limit<System> = Limit::new(4_000_000, System);

fn main() {
    let _huge_vec: Vec<u8> = Vec::with_capacity(4_000_001);
}

You can run that example locally and see how the process crashes:

$ cargo run --example huge_vec
memory allocation of 4000001 bytes failed
Aborted
Commit count: 4

cargo fmt