shared_memory
This crate provides a simple interface to shared memory OS APIs.
Shared memory is well suited for sharing large amounts of data between processes as it relies purely on memory accesses. Other than when managing concurent access through locks/events, reading and writing memory from a SharedMem relies only on CPU features (the operating system is not involved, no context switches like system calls, etc...).
Usage
Writer based on examples/create.rs
//Creates a new SharedMem link "shared_mem.link" that points to shared memory of size 4096
let mut my_shmem: SharedMem = match create.unwrap;
//Acquire write lock
Reader based on examples/open.rs
// Open an existing SharedMem link named "shared_mem.link"
let mut my_shmem: SharedMem = match open.unwrap;
//Aquire Read lock
Operating System Support
Feature | Description | Linux | Windows | Mac[1] |
---|---|---|---|---|
SharedMem.create/open | Create/open a SharedMem | ✔ | ✔ | X |
SharedMem.*_raw | Create/open a raw shared memory map | ✔ | ✔ | X |
LockType::Mutex | Mutually exclusive lock | ✔ | ✔ | X |
LockType::RwLock | Exlusive write/shared read | ✔ | X[2] | X |
[1] I do not own a Mac so cannot implement that side of things myself. Contributions are welcome !
[2] Windows provides no default implementation of Rwlock that is safe to share between processes. See Issue #1
License
Contribution
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.