Add FixedSizeBlockAllocator::fallback_alloc method

This commit is contained in:
Philipp Oppermann
2020-01-20 14:05:01 +01:00
parent 9b7326541e
commit d636939b51

View File

@@ -1,3 +1,6 @@
use alloc::alloc::Layout;
use core::ptr;
/// The block sizes to use.
///
/// The sizes must each be power of 2 because they are also used as
@@ -30,4 +33,12 @@ impl FixedSizeBlockAllocator {
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
self.fallback_allocator.init(heap_start, heap_size);
}
/// Allocates using the fallback allocator.
fn fallback_alloc(&mut self, layout: Layout) -> *mut u8 {
match self.fallback_allocator.allocate_first_fit(layout) {
Ok(ptr) => ptr.as_ptr(),
Err(_) => ptr::null_mut(),
}
}
}