polymock

Crates.iopolymock
lib.rspolymock
version0.2.2
sourcesrc
created_at2023-01-19 17:11:12.480904
updated_at2023-03-17 15:16:25.965897
descriptionA thread-safe arena bytes allocator
homepage
repositoryhttps://github.com/MrGunflame/polymock-rs
max_upload_size
id762708
size68,932
0xc0001a2040 (MrGunflame)

documentation

https://docs.rs/polymock

README

polymock

Crates.io Docs.rs

A thread-safe bump allocation arena for bytes.

polymock is primarly targeted at high-throughput multi-threaded network applications which need to allocate and free buffers very frequently and cannot afford going through the global allocator.

Usage

Add polymock to your Cargo.toml:

polymock = "0.2.0"

Next create an allocation arena and allocate some buffers:

use polymock::Arena;

// Create a bump arena with a chunk size of 1000 bytes.
let arena = Arena::new(1000);

let mut buffers = Vec::new();
for _ in 0..10 {
    // All 10 buffers will be allocated in the same chunk.
    let buf = arena.alloc();

    buffers.push(buf);
}

// The allocated buffers may outlive the arena they
// were allocated with.

drop(arena);

buffers[0][0] = 1;

License

Licensed under either MIT License or Apache License, Version 2.0 at your option.

Commit count: 53

cargo fmt