Function madvise::madvise
[−]
[src]
pub unsafe fn madvise(
ptr: *const u8,
len: usize,
advice: AccessPattern
) -> Result<()>
Raw advise wrapper with proper error handling. This enforces the same contract as
libc::madvise
. Specifically, ptr
must be non-null and the data between ptr
and ptr + len
must be initialized.
Example
use madvise::{AccessPattern, madvise}; use std::mem; struct BigStruct([u8; 1024]); let mut heap_allocated_big_struct = Box::new(BigStruct([0; 1024])); unsafe { madvise( Box::as_ref(&heap_allocated_big_struct) as *const BigStruct as *const u8, mem::size_of::<BigStruct>(), AccessPattern::Sequential ).expect("Advisory failed"); } for i in heap_allocated_big_struct.0.iter_mut() { *i += 1 }