Struct buddy_system_allocator::Heap
source · [−]pub struct Heap { /* private fields */ }
Expand description
A heap that uses buddy system
Usage
Create a heap and add a memory region to it:
use buddy_system_allocator::*;
let mut heap = Heap::empty();
unsafe {
heap.init(begin, size);
// or
heap.add_to_heap(begin, end);
}
Implementations
sourceimpl Heap
impl Heap
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 RefUnwindSafe for Heap
impl Send for Heap
impl !Sync for Heap
impl Unpin for Heap
impl UnwindSafe for Heap
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more