mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-12 01:51:34 +11:00
Extract current alloc to a new_block function
This commit is contained in:
parent
d372ca74bf
commit
e80ad601a3
|
@ -39,10 +39,8 @@ impl BlockAllocator {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for BlockAllocator {
|
unsafe fn new_block(&self, layout: Layout) -> *mut u8 {
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
||||||
let block_layout = Layout::new::<Block>();
|
let block_layout = Layout::new::<Block>();
|
||||||
let (overall_layout, offset) = block_layout.extend(layout).expect("Overflow on allocation");
|
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)
|
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) {
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||||
let block = Block::from_data_ptr(ptr, layout);
|
let block = Block::from_data_ptr(ptr, layout);
|
||||||
|
|
Loading…
Reference in a new issue