Struct veryfast::pool::Pool
[−]
[src]
pub struct Pool<T> { /* fields omitted */ }
A fast heap-allocator. Allocates objects in a batch, but transfers the ownership to the Object
.
Allocations will first check if there is an already free slot to use, and use that. If no, It will take a lock and allocate a batch of memory.
When objects are dropped, their memory will be returned to the pool to be used again later.
The memory of the batches will be deallocated only when the Pool
and all the related Object
s
are dropped.
Methods
impl<T> Pool<T>
[src]
fn new() -> Pool<T>
[src]
Creates a new Pool
.
fn with_params(align_to_cache: bool) -> Pool<T>
[src]
Creates a new Pool
.
align_to_cache
: Should each object be on a separate CPU cache line. Speeds up multithreaded usage, but hurts single-threaded cache locality a bit and requires a bit more memory. Has no effect ifsize_of::<T>
is already a multiple of a cache line size.
fn with_system_params(
align_to_cache: bool,
cache_line_size: usize,
number_of_sets: usize
) -> Pool<T>
[src]
align_to_cache: bool,
cache_line_size: usize,
number_of_sets: usize
) -> Pool<T>
Creates a new Pool
.
align_to_cache
: Should each object be on a separate CPU cache line. Speeds up multithreaded usage, but hurts single-threaded cache locality a bit and requires a bit more memory. Has no effect ifsize_of::<T>
is already a multiple of a cache line size.cache_line_size
: The size of an L1 cache line on the architecture. Must be a power of 2.number_of_sets
: The number of associativity sets of the target processor. Decides the size of batch allocations.
fn push(&self, obj: T) -> Object<T>
[src]
Save the object on the heap. Will get a pointer that will drop it's content when
dropped (like a Box
). The memory will be reused though!
Thread-safe. Very fast most of the time, but will take a bit longer if need to allocate more objects.
Will panic if out of memory.