Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created May 9, 2018 16:01
Show Gist options
  • Save alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3 to your computer and use it in GitHub Desktop.
Save alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3 to your computer and use it in GitHub Desktop.
#![feature(asm)]
use std::ptr;
fn black_box<T>(t: &T) {
unsafe { asm!("" : : "r"(t)); }
}
fn main() {
let mut x = Vec::<u8>::with_capacity(1024 * 1024 * 1024);
for _ in 0..10 {
black_box(&x);
black_box(&x.as_ptr());
let a = x.as_ptr();
let b = x.as_mut_ptr();
black_box(&a);
black_box(&b);
let c = x.capacity();
black_box(&c);
unsafe {
ptr::copy(a, b, c);
}
black_box(&x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment