From a5f9c232db07277f50dde331656a437015d42f37 Mon Sep 17 00:00:00 2001 From: Claudio Giovanni Mattera Date: Wed, 3 Nov 2021 16:41:25 +0100 Subject: [PATCH] Use memory addresses instead of creating static arrays in Rust template Static arrays will increase the size of the cartridge, because at runtime they will be initialized with the values used in the source (which is then ignored by the allocator). --- cli/assets/templates/rust/src/alloc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/assets/templates/rust/src/alloc.rs b/cli/assets/templates/rust/src/alloc.rs index 92d488ec..94ac1266 100644 --- a/cli/assets/templates/rust/src/alloc.rs +++ b/cli/assets/templates/rust/src/alloc.rs @@ -5,12 +5,12 @@ const FAST_HEAP_SIZE: usize = 4 * 1024; // 4 KB const HEAP_SIZE: usize = 16 * 1024; // 16 KB const LEAF_SIZE: usize = 16; -static mut FAST_HEAP: [u8; FAST_HEAP_SIZE] = [0u8; FAST_HEAP_SIZE]; -static mut HEAP: [u8; HEAP_SIZE] = [0u8; HEAP_SIZE]; +static mut FAST_HEAP: *mut [u8; FAST_HEAP_SIZE] = (0x10000 - HEAP_SIZE - FAST_HEAP_SIZE) as *mut [u8; FAST_HEAP_SIZE]; +static mut HEAP: *mut [u8; HEAP_SIZE] = (0x10000 - HEAP_SIZE) as *mut [u8; HEAP_SIZE]; #[global_allocator] static ALLOC: NonThreadsafeAlloc = unsafe { - let fast_param = FastAllocParam::new(FAST_HEAP.as_ptr(), FAST_HEAP_SIZE); - let buddy_param = BuddyAllocParam::new(HEAP.as_ptr(), HEAP_SIZE, LEAF_SIZE); + let fast_param = FastAllocParam::new(FAST_HEAP as *mut u8, FAST_HEAP_SIZE); + let buddy_param = BuddyAllocParam::new(HEAP as *mut u8, HEAP_SIZE, LEAF_SIZE); NonThreadsafeAlloc::new(fast_param, buddy_param) };