summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch6/ch6-memscan-2/src/main.rs
blob: 3784436bf4da939f27285925352dd60f6ac8fdd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut n_nonzero = 0;  

    for i in 1..10000 { // <1>
        let ptr = i as *const u8;    
        let byte_at_addr = unsafe { *ptr }; 

        if byte_at_addr != 0 {
            n_nonzero += 1;
        }
    }

    println!("non-zero bytes in memory: {}", n_nonzero);
}