Skip to content

A fixed size allocator for single typed, constant time (de)allocations.

Notifications You must be signed in to change notification settings

RobinWebbers/memory-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

memory-pool

A fixed-size block allocator for constant time (de)allocations.

The memory pool reserves a fixed size of (virtual) memory and does not grow with new allocations. We store a pointer in free entries, so types smaller than a pointer have additional space overhead. The flipside is that we can rapidly allocate and free entries, no matter the access pattern.

The primary use case of this crate is as a performance optimisation for (de)allocation heavy code.

Example

#![feature(allocator_api)]
use memory_pool::MemoryPool;
use std::alloc::Layout;

struct Data {
    inner: usize,
}

let capacity = 2_usize.pow(20);
let pool = MemoryPool::new(capacity, Layout::new::<Data>());

let elem = Box::new_in(Data { inner: 0 }, &pool);

// We can deallocate during the lifetime of pool
drop(elem);

// This new element can reuse the memory we freed
let elem = Box::new_in(Data { inner: 5 }, &pool);

About

A fixed size allocator for single typed, constant time (de)allocations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages