| Crates.io | memadvise |
| lib.rs | memadvise |
| version | 0.1.2 |
| created_at | 2017-10-10 13:27:52.709435+00 |
| updated_at | 2017-10-12 17:52:17.833987+00 |
| description | Advises operating system about memory usage |
| homepage | https://github.com/Elzair/memadvise |
| repository | https://github.com/Elzair/memadvise |
| max_upload_size | |
| id | 35097 |
| size | 44,261 |
memadvise is a Rust crate that can provide 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.
extern crate memadvise;
extern crate page_size;
fn main() {
// 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.
}
memadvise features five different 'hints' used to tell the system how a program will use a certain range of memory.
Normal - no special usage
Random - will use range but in no particular order; OS should not read ahead much
WillNeed - will use range; OS should read ahead more than Random
Sequential - will use range in order; OS should read ahead more than WillNeed
DontNeed - will not use range right now; OS can swap it to disk
memadvise should Work on Windows and any POSIX compatible system (Linux, Mac OSX, etc.).
memadvise is continuously tested on:
x86_64-unknown-linux-gnu (Linux)i686-unknown-linux-gnux86_64-unknown-linux-musl (Linux w/ MUSL)i686-unknown-linux-muslx86_64-apple-darwin (Mac OSX)i686-apple-darwinx86_64-pc-windows-msvc (Windows)i686-pc-windows-msvcx86_64-pc-windows-gnui686-pc-windows-gnumemadvise is continuously cross-compiled for:
arm-unknown-linux-gnueabihfaarch64-unknown-linux-gnumips-unknown-linux-gnuaarch64-unknown-linux-musli686-linux-androidx86_64-linux-androidarm-linux-androideabiaarch64-linux-androidi386-apple-iosx86_64-apple-iosi686-unknown-freebsdx86_64-unknown-freebsdx86_64-unknown-netbsdasmjs-unknown-emscripten