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§
source§impl<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, start+size) 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