zallocator 0.5.1

Amortizes the cost of small allocations by allocating memory in bigger chunks.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use zallocator::pool::AllocatorPool;

#[tokio::main]
async fn main() {
    let pool = AllocatorPool::with_task(2, tokio::time::Duration::from_millis(1000), tokio::spawn);
    let a = pool.fetch(1024, "a").unwrap();
    let b = pool.fetch(1024, "b").unwrap();
    pool.put(a);
    pool.put(b);

    assert_eq!(2, pool.idles());

    pool.fetch(1024, "c").unwrap();
    tokio::time::sleep(core::time::Duration::from_millis(1000)).await;
    assert_eq!(1, pool.idles());
    tokio::time::sleep(core::time::Duration::from_millis(2000)).await;
    assert_eq!(0, pool.idles());
}