6个稳定版本

1.0.5 2024年3月28日
1.0.4 2021年11月7日
1.0.3 2021年11月4日

103内存管理 中排名

Download history 173/week @ 2024-04-15 399/week @ 2024-04-22 275/week @ 2024-04-29 283/week @ 2024-05-06 323/week @ 2024-05-13 785/week @ 2024-05-20 733/week @ 2024-05-27 423/week @ 2024-06-03 541/week @ 2024-06-10 423/week @ 2024-06-17 315/week @ 2024-06-24 90/week @ 2024-07-01 301/week @ 2024-07-08 376/week @ 2024-07-15 934/week @ 2024-07-22 765/week @ 2024-07-29

2,385 每月下载量
7 个Crates中使用(通过 lib-ruby-parser

MIT 许可证

9KB
245

alloc-from-pool

此crate实现了对象池。

基本用法

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);

基准测试

您可以使用 cargo bench 运行

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

无运行时依赖