https://github.com/jeronimosg/typed_shmem
Simple, typed shared memory crate.
https://github.com/jeronimosg/typed_shmem
crates ipc mapped-file rust shared-memory
Last synced: 7 months ago
JSON representation
Simple, typed shared memory crate.
- Host: GitHub
- URL: https://github.com/jeronimosg/typed_shmem
- Owner: jeronimosg
- License: apache-2.0
- Created: 2020-09-16T19:35:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-28T15:43:49.000Z (almost 5 years ago)
- Last Synced: 2025-06-02T03:40:22.690Z (8 months ago)
- Topics: crates, ipc, mapped-file, rust, shared-memory
- Language: Rust
- Homepage: https://crates.io/crates/typed_shmem
- Size: 67.4 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typed_shmem
Exposes shared memory on *nix and Windows using mapped files. This work is heavily inspired on the [shared_memory](https://crates.io/crates/shared_memory) crate, but instead of being just a copy cat, **typed_shmem** provides a typed mapping into the shared memory region.
## Usage
First, a process must create the shared region:
```rust
use typed_shmem as sh;
use typed_shmem::error::ShMemErr;
use typed_shmem::common::ShMemOps;
fn main() -> Result<(), ShMemErr> {
let mut mem = sh::ShMemCfg::::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:
```rust
use typed_shmem as sh;
use typed_shmem::error::ShMemErr;
use typed_shmem::common::ShMemOps;
fn main() -> Result<(), ShMemErr> {
let mut mem = sh::ShMemCfg::::default()
.on_file("test_program")
.build()?;
let val = unsafe { mem.get_t() };
assert_eq!(*val, 10);
Ok(())
}
```
## To-Do (no specific order)
- [x] Implement custom error instead of `Box`ing everything.
- [ ] Implement optional sharing/syncronization mechanisims.
- [ ] Check and rewrite the unsafe blocks (bugs there for sure).
- [ ] Create tests (using `fork()` in *nix (not sure)?; windows?).
- [ ] More to come...
## Contributions
All contributions to this project will be under **Apache-2.0** license.