#single-threaded

alloc-from-pool

Single-threaded object pool implementation

6 stable releases

1.0.5 Mar 28, 2024
1.0.4 Nov 7, 2021
1.0.3 Nov 4, 2021

#6 in #single-threaded

Download history 91/week @ 2024-07-02 409/week @ 2024-07-09 303/week @ 2024-07-16 1121/week @ 2024-07-23 618/week @ 2024-07-30 857/week @ 2024-08-06 1095/week @ 2024-08-13 1097/week @ 2024-08-20 1166/week @ 2024-08-27 724/week @ 2024-09-03 657/week @ 2024-09-10 761/week @ 2024-09-17 951/week @ 2024-09-24 816/week @ 2024-10-01 680/week @ 2024-10-08 973/week @ 2024-10-15

3,558 downloads per month
Used in 7 crates (via lib-ruby-parser)

MIT license

9KB
245 lines

alloc-from-pool

This crate implements object pool.

Basic usage

use alloc_from_pool::Pool;

// dummy struct
struct Foo([u8; 50]);

// pool has size = 0 by default
let pool = Pool::<Foo>::new();

// performs allocation
let foo1 = pool.alloc(Foo([1; 50]));
// returns memory back to pool
drop(foo1);

// re-uses the value that we've just returned back to pool
let foo2 = pool.alloc(Foo([2; 50]));
// returns memory back to pool
drop(foo2);

// 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(Foo([3; 50]));
// it uses the same pool, and also returns back to the same pool
drop(foo3);

Benchmarks

You can run cargo bench:

test alloc_with_box  ... bench:          56 ns/iter (+/- 6)
test alloc_with_pool ... bench:           7 ns/iter (+/- 0)

No runtime deps