Struct buddy_system_allocator::Heap
source · [−]pub struct Heap<const ORDER: usize> { /* private fields */ }Expand description
A heap that uses buddy system with configurable order.
Usage
Create a heap and add a memory region to it:
use buddy_system_allocator::*;
let mut heap = Heap::<32>::empty();
unsafe {
heap.init(begin, size);
// or
heap.add_to_heap(begin, end);
}Implementations
sourceimpl<const ORDER: usize> Heap<ORDER>
impl<const ORDER: usize> Heap<ORDER>
sourcepub unsafe fn add_to_heap(&mut self, start: usize, end: usize)
pub unsafe fn add_to_heap(&mut self, start: usize, end: usize)
Add a range of memory [start, end) to the heap
sourcepub unsafe fn init(&mut self, start: usize, size: usize)
pub unsafe fn init(&mut self, start: usize, size: usize)
Add a range of memory [start, end) to the heap
sourcepub fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, ()>
pub fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, ()>
Alloc a range of memory from the heap satifying layout requirements
sourcepub fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
pub fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
Dealloc a range of memory from the heap
sourcepub fn stats_alloc_user(&self) -> usize
pub fn stats_alloc_user(&self) -> usize
Return the number of bytes that user requests
sourcepub fn stats_alloc_actual(&self) -> usize
pub fn stats_alloc_actual(&self) -> usize
Return the number of bytes that are actually allocated
sourcepub fn stats_total_bytes(&self) -> usize
pub fn stats_total_bytes(&self) -> usize
Return the total number of bytes in the heap
Trait Implementations
Auto Trait Implementations
impl<const ORDER: usize> RefUnwindSafe for Heap<ORDER>
impl<const ORDER: usize> Send for Heap<ORDER>
impl<const ORDER: usize> !Sync for Heap<ORDER>
impl<const ORDER: usize> Unpin for Heap<ORDER>
impl<const ORDER: usize> UnwindSafe for Heap<ORDER>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more