Skip to content

Instantly share code, notes, and snippets.

@cutewalker
Last active March 24, 2016 02:03
Show Gist options
  • Save cutewalker/cf5d25aa225c9ab121da to your computer and use it in GitHub Desktop.
Save cutewalker/cf5d25aa225c9ab121da to your computer and use it in GitHub Desktop.
use std::mem;
fn main() {
let a = 3i64;
let b = [1, 2, 3, 4, 5, 6];
//let c = &b[2..5];
//let c = 3i64;
let c = "abcasdfafjekfahasid";
let d = &b;
println!("{}, {}, {}, {}",
mem::size_of_val(&a),
mem::size_of_val(&b),
mem::size_of_val(&c),
mem::size_of_val(&d),
);
println!("{:p}, {:p}, {:p}, {:p}", &a, &b, &c, &d);
unsafe {
let s: *const u8 = mem::transmute(&d);
let e: *const u8 = mem::transmute(&a);
let mut p = s;
let mut count = 0;
while p < e {
if count % 8 == 0 {
print!("\n{:p} -> ", p);
}
print!(" {:02x}", *p);
p = p.offset(1);
count += 1;
}
println!("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment