2个版本
使用旧的Rust 2015
0.1.1 | 2018年4月23日 |
---|---|
0.1.0 | 2018年4月20日 |
#6 in #multi-process
15KB
279 行
这是为Rust实现的共享内存的多进程功能
一个用于套接字的Rust库。
使用方法
将其添加到您的 Cargo.toml
[dependencies]
share_memory = "0.1"
并将其添加到您的crate根目录
extern crate share_memory;
如何使用
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 {
}
}
现在它会打印1,如果您启动多进程,如果更改数据
// unix为name和path_name得到共享内存的索引
// windows由name得到共享内存的索引,将忽略path_name
pub fn new_create(name: String, size: usize, path_name: Option<String>) -> Result<ShareMemory>;
许可证
许可为以下之一
- Apache许可证第2版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确表示,否则根据Apache-2.0许可证定义,您有意提交给作品的所有贡献,将按上述方式双许可,不附加任何额外条款或条件。
依赖关系
~1–270KB