Extract current alloc to a new_block function

This commit is contained in:
Gwilym Kuiper 2021-08-16 22:33:56 +01:00
parent d372ca74bf
commit e80ad601a3

View file

@ -39,10 +39,8 @@ impl BlockAllocator {
}),
}
}
}
unsafe impl GlobalAlloc for BlockAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe fn new_block(&self, layout: Layout) -> *mut u8 {
let block_layout = Layout::new::<Block>();
let (overall_layout, offset) = block_layout.extend(layout).expect("Overflow on allocation");
@ -70,6 +68,12 @@ unsafe impl GlobalAlloc for BlockAllocator {
block_ptr.as_ptr().cast::<u8>().add(offset)
}
}
unsafe impl GlobalAlloc for BlockAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
self.new_block(layout)
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
let block = Block::from_data_ptr(ptr, layout);