mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 18:08:56 -06:00
Fix
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
|
unsafe { *ptr = i };
|
||||||
|
|
||||||
|
xs.push(ptr as usize | BITS);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
handle.join().unwrap();
|
for x in xs {
|
||||||
|
println!("{}", unsafe { *((x & !BITS) as *mut usize) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user