Crates.io | bufferpool |
lib.rs | bufferpool |
version | 0.1.7 |
source | src |
created_at | 2019-12-08 06:52:10.37023 |
updated_at | 2019-12-26 05:11:40.136026 |
description | A vector of vectors backed by one contiguous vector - allows mutable borrows of non-overlapping regions. |
homepage | |
repository | https://github.com/bennetthardwick/buffer-pool |
max_upload_size | |
id | 187252 |
size | 26,289 |
A Rust "vector of vectors" backed by one contiguous vector. Allows mutable borrows of non-overlapping buffers.
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.
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);