This commit is contained in:
Yota Toyama
2023-09-28 15:11:23 +10:00
parent 25631ef919
commit 1aaf2fb621

View File

@@ -1,7 +1,7 @@
extern crate bdwgc_alloc;
use bdwgc_alloc::Allocator; use bdwgc_alloc::Allocator;
use std::alloc::Layout; use std::alloc::{alloc, Layout};
const BITS: usize = 7 << 48;
#[global_allocator] #[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator; static GLOBAL_ALLOCATOR: Allocator = Allocator;
@@ -9,13 +9,17 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() { fn main() {
unsafe { Allocator::initialize() } unsafe { Allocator::initialize() }
let handle = std::thread::spawn(move || { let mut xs = vec![];
unsafe { Allocator::register_current_thread().unwrap() }
loop { for i in 0..10000000 {
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; let ptr = unsafe { alloc(Layout::new::<usize>()) } as *mut usize;
}
});
handle.join().unwrap(); unsafe { *ptr = i };
xs.push(ptr as usize | BITS);
}
for x in xs {
println!("{}", unsafe { *((x & !BITS) as *mut usize) });
}
} }