alloc-from-pool
This crate implements object pool.
Basic usage
use Pool;
// dummy struct
;
// pool has size = 0 by default
let pool = new;
// performs allocation
let foo1 = pool.alloc;
// returns memory back to pool
drop;
// re-uses the value that we've just returned back to pool
let foo2 = pool.alloc;
// returns memory back to pool
drop;
// it also possible to create a Factory based on a pool
// that holds a reference to initial Pool
let factory = pool.factory;
// Factory has the same `alloc` method:
let foo3 = factory.alloc;
// it uses the same pool, and also returns back to the same pool
drop;
Benchmarks
You can run cargo bench
:
test alloc_with_box ... bench: 56 ns/iter (+/- 6)
test alloc_with_pool ... bench: 7 ns/iter (+/- 0)