Struct drone_core::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]
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.
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.
fn size(&self) -> usize
[src]
Returns the pool size.
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.
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.