You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A thread-safe object pool with automatic return and attach/detach semantics
The goal of an object pool is to reuse expensive to allocate objects or frequently allocated objects
Common use case is when using buffer to read IO
You would create a Pool of size n, containing Vec that can be used to call something like file.read_to_end(buff)
Usage
[dependencies]
object-pool = "0.1"
externcrate object_pool;
Basic usage for pulling from the pool
let pool:Pool<Vec<u8>> = Pool::new(32, || Vec::with_capacity(4096);letmut reusable_buff = pool.pull().unwrap();
reusable_buff.clear();
some_file.read_to_end(reusable_buff.deref_mut());//reusable_buff falls out of scope and is returned to the pool
For access across multiple threads simply wrap the pool in an Arc
let pool:Arc<Pool<T>> = Pool::new(cap, || T::new();