Struct drone::heap::Pool
[−]
[src]
pub struct Pool { /* fields omitted */ }
A lock-free fixed-size blocks allocator.
The Pool
allows lock-free O(1) allocations, deallocations, and
initialization.
A Pool
consists of capacity
number of fixed-size blocks. It maintains a
free list of deallocated blocks.
Methods
impl Pool
[src]
pub const fn new(offset: usize, size: usize, capacity: usize) -> Self
[src]
Creates an empty Pool
.
The returned pool needs to be further initialized with init
method.
Resulting location of the pool should be the sum of offset
argument
provided to the current method and start
argument for init
method.
pub unsafe fn init(&mut self, start: &mut usize)
[src]
Initializes the pool with start
address.
This operation should compute in O(1) time.
Safety
- Must be called no more than once.
- Must be called before using the pool.
pub fn size(&self) -> usize
[src]
Returns the pool size.
pub fn alloc(&self) -> Option<NonZero<*mut u8>>
[src]
Allocates a fixed-size block of memory. Returns None
if the pool is
exhausted.
This operation should compute in O(1) time.
pub unsafe fn dealloc(&self, ptr: *mut u8)
[src]
Deallocates a fixed-size block of memory referenced by ptr
.
This operation should compute in O(1) time.
Safety
ptr
should not be used after deallocation.