From d372ca74bf8b4cbc74a6f8121d30fa5c4c235d23 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 16 Aug 2021 22:31:10 +0100 Subject: [PATCH] Use the block allocator by default now --- agb/src/agb_alloc/block_allocator.rs | 12 ++++++++++++ agb/src/agb_alloc/mod.rs | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) 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) -> ! {