Crate mem_file [] [src]

Provides a wrapper around native shared memory for Linux and Windows.

This crate is ideal if you need to share large amounts of data with another process purely through memory.

Examples

Creator based on examples/create.rs

//Create a MemFile at `pwd`\test.txt of size 4096
let mut mem_file: MemFile = match MemFile::create(PathBuf::from("test.txt"), 4096) {<...>};
//Set explicit scope for the lock (no need to call drop(shared_data))
{
    //Acquire write lock
    let mut shared_data = match mem_file.wlock_as_slice::<u8>() {<...>};
    let src = b"Some string you want to share\x00";
    //Write to the shared memory
    shared_data[0..src.len()].copy_from_slice(src);
}

Slave based on examples/open.rs

let mut mem_file: MemFile = match MemFile::open(PathBuf::from("test.txt")) {<...>};
//Set explicit scope for the lock (no need to call drop(shared_data))
{
    //Acquire read lock
    let mut shared_data = match mem_file.rlock_as_slice::<u8>() {<...>};
    //Print the content of the shared memory as chars
    for byte in &shared_data[0..256] {
        if *byte == 0 { break; }
        print!("{}", *byte as char);
    }
}

Structs

MemFile

Struct used to manipulate the shared memory

MemFileRLock

Non-exclusive read lock holding a reference to shared memory

MemFileRLockSlice

Non-exclusive read lock holding a reference to a slice of shared memory

MemFileWLock

Exclusive write lock holding a reference to shared memory

MemFileWLockSlice

Exclusive write lock holding a reference to a slice of shared memory

Traits

MemFileCast

Read WARNING before use