diff --git a/examples/non_threadsafe_demo.rs b/examples/non_threadsafe_demo.rs index b1d1d37..3a9855d 100644 --- a/examples/non_threadsafe_demo.rs +++ b/examples/non_threadsafe_demo.rs @@ -4,17 +4,21 @@ const FAST_HEAP_SIZE: usize = 32 * 1024; // 32 KB const HEAP_SIZE: usize = 1024 * 1024; // 1M const LEAF_SIZE: usize = 16; -pub static mut FAST_HEAP: [u8; FAST_HEAP_SIZE] = [0u8; FAST_HEAP_SIZE]; -pub static mut HEAP: [u8; HEAP_SIZE] = [0u8; HEAP_SIZE]; +#[repr(align(64))] +struct Heap([u8; S]); + +static mut FAST_HEAP: Heap = Heap([0u8; FAST_HEAP_SIZE]); +static mut HEAP: Heap = Heap([0u8; HEAP_SIZE]); // This allocator can't work in tests since it's non-threadsafe. #[cfg_attr(not(test), 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.0.as_ptr(), FAST_HEAP_SIZE); + let buddy_param = BuddyAllocParam::new(HEAP.0.as_ptr(), HEAP_SIZE, LEAF_SIZE); NonThreadsafeAlloc::new(fast_param, buddy_param) }; +#[allow(clippy::useless_vec)] fn main() { let v = vec![0u8; 42]; let msg = "alloc success".to_string(); diff --git a/examples/non_threadsafe_test.rs b/examples/non_threadsafe_test.rs index 6097c61..3495c47 100644 --- a/examples/non_threadsafe_test.rs +++ b/examples/non_threadsafe_test.rs @@ -4,17 +4,21 @@ const FAST_HEAP_SIZE: usize = 32 * 1024; // 32 KB const HEAP_SIZE: usize = 1024 * 1024; // 1M const LEAF_SIZE: usize = 16; -pub static mut FAST_HEAP: [u8; FAST_HEAP_SIZE] = [0u8; FAST_HEAP_SIZE]; -pub static mut HEAP: [u8; HEAP_SIZE] = [0u8; HEAP_SIZE]; +#[repr(align(64))] +struct Heap([u8; S]); + +static mut FAST_HEAP: Heap = Heap([0u8; FAST_HEAP_SIZE]); +static mut HEAP: Heap = Heap([0u8; HEAP_SIZE]); // This allocator can't work in tests since it's non-threadsafe. #[cfg_attr(not(test), 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.0.as_ptr(), FAST_HEAP_SIZE); + let buddy_param = BuddyAllocParam::new(HEAP.0.as_ptr(), HEAP_SIZE, LEAF_SIZE); NonThreadsafeAlloc::new(fast_param, buddy_param) }; +#[allow(clippy::useless_vec)] fn main() { let v = vec![0u8; 32]; drop(v);