diff --git a/agb/src/agb_alloc/block_allocator.rs b/agb/src/agb_alloc/block_allocator.rs index 9ca55fa4..2e903381 100644 --- a/agb/src/agb_alloc/block_allocator.rs +++ b/agb/src/agb_alloc/block_allocator.rs @@ -29,6 +29,18 @@ pub(crate) struct BlockAllocator { state: Mutex, } +impl BlockAllocator { + pub(super) const unsafe fn new() -> Self { + Self { + inner_allocator: BumpAllocator::new(), + state: Mutex::new(BlockAllocatorState { + first_block: None, + last_block: None, + }), + } + } +} + unsafe impl GlobalAlloc for BlockAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { let block_layout = Layout::new::(); diff --git a/agb/src/agb_alloc/mod.rs b/agb/src/agb_alloc/mod.rs index ec01fb04..b67ff9ff 100644 --- a/agb/src/agb_alloc/mod.rs +++ b/agb/src/agb_alloc/mod.rs @@ -3,12 +3,12 @@ use core::alloc::Layout; mod block_allocator; mod bump_allocator; -use bump_allocator::BumpAllocator; +use block_allocator::BlockAllocator; const EWRAM_END: usize = 0x0204_0000; #[global_allocator] -static GLOBAL_ALLOC: BumpAllocator = BumpAllocator::new(); +static GLOBAL_ALLOC: BlockAllocator = unsafe { BlockAllocator::new() }; #[alloc_error_handler] fn alloc_error(layout: Layout) -> ! {