Crates.io | typed_shmem |
lib.rs | typed_shmem |
version | 0.3.0 |
source | src |
created_at | 2020-10-20 19:20:08.969315 |
updated_at | 2021-03-28 15:45:29.558497 |
description | Typed shared memory crate for *nix and Windows. |
homepage | |
repository | https://www.github.com/UpsettingBoy/typed_shmem |
max_upload_size | |
id | 303632 |
size | 30,570 |
Exposes shared memory on *nix and Windows using mapped files. This work is heavily inspired on the shared_memory crate, but instead of being just a copy cat, typed_shmem provides a typed mapping into the shared memory region.
First, a process must create the shared region:
use typed_shmem as sh;
use typed_shmem::error::ShMemErr;
use typed_shmem::common::ShMemOps;
fn main() -> Result<(), ShMemErr> {
let mut mem = sh::ShMemCfg::<u32>::default()
.set_owner()
.on_file("test_program")
.build()?;
//Writing
unsafe { *mem.get_t_mut() = 10; }
//Reading
let val = unsafe { mem.get_t() };
assert_eq!(*val, 10);
loop {} //Used to keep the process alive, thus the allocated shared memory too.
Ok(())
Then, any other process can join the same region:
use typed_shmem as sh;
use typed_shmem::error::ShMemErr;
use typed_shmem::common::ShMemOps;
fn main() -> Result<(), ShMemErr> {
let mut mem = sh::ShMemCfg::<u32>::default()
.on_file("test_program")
.build()?;
let val = unsafe { mem.get_t() };
assert_eq!(*val, 10);
Ok(())
}
Box<dyn Error>
ing everything.fork()
in *nix (not sure)?; windows?).All contributions to this project will be under Apache-2.0 license.