Skip to content

Commit a5f9c23

Browse files
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).
1 parent eb9e1a6 commit a5f9c23

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cli/assets/templates/rust/src/alloc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const FAST_HEAP_SIZE: usize = 4 * 1024; // 4 KB
55
const HEAP_SIZE: usize = 16 * 1024; // 16 KB
66
const LEAF_SIZE: usize = 16;
77

8-
static mut FAST_HEAP: [u8; FAST_HEAP_SIZE] = [0u8; FAST_HEAP_SIZE];
9-
static mut HEAP: [u8; HEAP_SIZE] = [0u8; HEAP_SIZE];
8+
static mut FAST_HEAP: *mut [u8; FAST_HEAP_SIZE] = (0x10000 - HEAP_SIZE - FAST_HEAP_SIZE) as *mut [u8; FAST_HEAP_SIZE];
9+
static mut HEAP: *mut [u8; HEAP_SIZE] = (0x10000 - HEAP_SIZE) as *mut [u8; HEAP_SIZE];
1010

1111
#[global_allocator]
1212
static ALLOC: NonThreadsafeAlloc = unsafe {
13-
let fast_param = FastAllocParam::new(FAST_HEAP.as_ptr(), FAST_HEAP_SIZE);
14-
let buddy_param = BuddyAllocParam::new(HEAP.as_ptr(), HEAP_SIZE, LEAF_SIZE);
13+
let fast_param = FastAllocParam::new(FAST_HEAP as *mut u8, FAST_HEAP_SIZE);
14+
let buddy_param = BuddyAllocParam::new(HEAP as *mut u8, HEAP_SIZE, LEAF_SIZE);
1515
NonThreadsafeAlloc::new(fast_param, buddy_param)
1616
};

0 commit comments

Comments
 (0)