Crate memadvise [] [src]

This crate provides the operating system with hints about memory access patterns. For example, if the user calls memadvise::advise() with Advice::Sequential, the kernel may start bringing memory pages into RAM (if they were on disk) starting at the beginning of the block of memory passed.


This example shows the basic usage of the crate.

Be careful when using this code, it's not being tested!
extern crate memadvise;
extern crate page_size;
// Allocate block of memory in a system specific manner.
// Get portion of memory block (must be aligned to system page size).
let address: *mut () = ... 
let length = 320000;
// Tell the OS to start loading this portion into RAM starting at the beginning.
memadvise::advise(address, length, Advice::Sequential).unwrap();
// Do something with this portion of memory.
// Tell the OS we do not need this portion right now.
// That way, the OS can safely swap it out to disk.
memadvise::advise(address, length, Advice::DontNeed).unwrap();

// Do some other stuff.

// Be sure to free block of memory (system specific) at the end.



The possible errors returned by advise()



This function gives the system advice about a certain block of memory.