Crates.io | limit-alloc |
lib.rs | limit-alloc |
version | 0.1.0 |
source | src |
created_at | 2022-07-09 13:28:40.260865 |
updated_at | 2022-07-09 13:28:40.260865 |
description | A custom allocator that allows to limit the available memory |
homepage | |
repository | https://github.com/Badel2/limit-alloc |
max_upload_size | |
id | 622530 |
size | 42,934 |
A custom allocator that allows to limit the available memory.
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