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