#atomic #garbage #non-blocking #lock-free


A thread-safe object pool with automatic return and attach/detach semantics

11 releases

✓ Uses Rust 2018 edition

0.3.1 Feb 6, 2019
0.3.0 Feb 6, 2019
0.2.3 Feb 3, 2019
0.1.6 Feb 2, 2019

#95 in Concurrency

Download history 83/week @ 2019-02-01 16/week @ 2019-02-08 16/week @ 2019-02-22 34/week @ 2019-03-01 13/week @ 2019-03-08 20/week @ 2019-03-15 52/week @ 2019-03-22

79 downloads per month


92 lines

Object Pool

License Cargo Documentation

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<u8> that can be used to call something like file.read_to_end(buff).


object-pool = "0.3"
extern crate object_pool;

Basic usage

let pool: Pool<Vec<u8>> = Pool::new(32, || Vec::with_capacity(4096));
let mut reusable_buff = pool.pull().unwrap();
//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());

Check out the docs for more examples


The benchmarks compare an alloc() vs a pool.pull() vs a pool.detach().

Check out the results