A user friendly crate that allows you to share memory between processes.
Writer based on examples/create.rs ``` rust //Creates a new SharedMem link "sharedmem.link" that points to shared memory of size 4096 let mut myshmem: SharedMem = match SharedMem::create( PathBuf::from("shared_mem.link"), LockType::Mutex, //Concurent accesses will be managed by a mutex 4096 ).unwrap();
//Acquire write lock
{
let mut shareddata: WriteLockGuardSlice
Reader based on examples/open.rs
rust
// Open an existing SharedMem link named "shared_mem.link"
let mut my_shmem: SharedMem = match SharedMem::open(PathBuf::from("shared_mem.link")).unwrap();
//Aquire Read lock
{
let mut shared_data = match my_shmem.rlock_as_slice::<u8>().unwrap();
//Print the content of the shared memory as chars
for byte in &shared_data[0..256] {
if *byte == 0 { break; }
print!("{}", *byte as char);
}
}
| Feature| Description | Linux | Windows| Mac[1]| |--------|-------------|:-----:|:------:|:----:| |SharedMem.create/open|Create/open a SharedMem|✔|✔|✔| |SharedMem.*_raw|Create/open a raw shared memory map|✔|✔|✔| |LockType::Mutex|Mutually exclusive lock|✔|✔|✔| |LockType::RwLock|Exlusive write/shared read|✔|X[2]|✔|
[1] I do not own a Mac so cannot properly test this library other than building against OSX.
[2] Windows provides no default implementation of Rwlock that is safe to share between processes. See Issue #1
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.