7 #![feature(allocator_api)]
8 #![feature(slice_ptr_get)]
13 use std::alloc::{Allocator, Global, Layout, System};
14 use std::sync::atomic::{AtomicUsize, Ordering};
17 static GLOBAL: custom::A = custom::A(AtomicUsize::new(0));
21 let n = GLOBAL.0.load(Ordering::SeqCst);
22 let layout = Layout::from_size_align(4, 2).unwrap();
24 let memory = Global.allocate(layout.clone()).unwrap();
25 helper::work_with(&memory);
26 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
27 Global.deallocate(memory.as_non_null_ptr(), layout);
28 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
30 let memory = System.allocate(layout.clone()).unwrap();
31 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
32 helper::work_with(&memory);
33 System.deallocate(memory.as_non_null_ptr(), layout);
34 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);