bufferpool

Crates.iobufferpool
lib.rsbufferpool
version0.1.7
sourcesrc
created_at2019-12-08 06:52:10.37023
updated_at2019-12-26 05:11:40.136026
descriptionA vector of vectors backed by one contiguous vector - allows mutable borrows of non-overlapping regions.
homepage
repositoryhttps://github.com/bennetthardwick/buffer-pool
max_upload_size
id187252
size26,289
Bennett Hardwick (bennetthardwick)

documentation

README

buffer-pool

Build Status

A Rust "vector of vectors" backed by one contiguous vector. Allows mutable borrows of non-overlapping buffers.

What is BufferPool

BufferPool is a crate that lets you get a slice of a certain size without having to allocate space for a new vector. It does this by pre-allocating a certain region of memory and then handing out references to slices inside this region. It's useful in applications such as audio programming, where allocating and freeing data can be expensive.

Usage

When creating a new BufferPool, it's recommended to use the BufferPoolBuilder interface. While it's completely possible to create a BufferPool yourself, it's less efficient if you know the size of the pool in advance.

let mut pool: BufferPool<usize> = BufferPoolBuilder::new()
    .with_buffer_size(1024)
    .with_capacity(100)
    .build();

let mut buffer = pool.get_cleared_space().unwrap();

for (index, value) in buffer.as_mut().iter_mut().enumerate() {
    *value = index;
}

let sum: usize = buffer.as_ref().iter().sum();

println!("Sum {}", sum);
Commit count: 20

cargo fmt