#memory #process #multi-process #cross-platform #shmget

share_memory

This is share memory impl multi process for rust

2 releases

Uses old Rust 2015

0.1.1 Apr 23, 2018
0.1.0 Apr 20, 2018

#8 in #multi-process

Download history 3/week @ 2023-11-09 1/week @ 2023-11-16 4/week @ 2023-11-23 10/week @ 2023-11-30 3/week @ 2023-12-07 2/week @ 2023-12-14 4/week @ 2023-12-21 4/week @ 2024-01-18 2/week @ 2024-01-25 2/week @ 2024-02-01 2/week @ 2024-02-08 26/week @ 2024-02-15 62/week @ 2024-02-22

92 downloads per month

Apache-2.0/MIT

15KB
279 lines

this is share memory impl multi process for rust

Build Status Crates.io

A Rust library for socket.

Usage

Add this to your Cargo.toml:

[dependencies]
share_memory = "0.1"

and this to your crate root:

extern crate share_memory;

How to use

extern crate share_memory;
extern crate time;
use share_memory::ShareMemory;
type ARRAY = [i32; 80];
fn main () {
    let size : usize = std::mem::size_of::<ARRAY>();
    let mut share = ShareMemory::new_create(String::from("."), size * 2, None).unwrap();
    if let Some(addr) = share.first_memory().ok().unwrap() {
        let mut data: &mut ARRAY = unsafe {
            std::mem::transmute(addr)
        };
        data[0] += 1;
        println!("{:?}", data[0]);
    }
    loop {
    }
}

now it will print 1, if you start multi process, if you change the data

// unix为name和path_name得到共享内存的索引
// windows由name得到共享内存的索引,将忽略path_name
pub fn new_create(name: String, size: usize, path_name: Option<String>) -> Result<ShareMemory>;

License

Licensed under either of

at your option.

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.

Dependencies

~1–265KB