1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (c) 2023 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! A [`SharedMemory`] is identified by a name and allows two processes to share memory with each
//! other (inter-process memory).
//!
//! One process creates the [`SharedMemory`] and multiple processes can then open the
//! [`SharedMemory`] with the [`SharedMemoryBuilder`].
//!
//! # Example
//!
//! ```
//! use iceoryx2_cal::shared_memory::*;
//! use iceoryx2_cal::named_concept::*;
//! use iceoryx2_cal::shm_allocator::pool_allocator::PoolAllocator;
//! use iceoryx2_cal::shm_allocator::pool_allocator;
//! use iceoryx2_bb_system_types::file_name::FileName;
//! use iceoryx2_bb_container::semantic_string::SemanticString;
//! use std::alloc::Layout;
//!
//! fn process_one<Shm: SharedMemory<PoolAllocator>>() {
//! let shm_name = FileName::new(b"myShmName").unwrap();
//! let allocator_config = pool_allocator::Config {
//! // we want to allocate [`u64`]
//! bucket_layout: Layout::new::<u64>()
//! };
//! let shm = Shm::Builder::new(&shm_name).size(1024).create(&allocator_config).unwrap();
//! let mut shm_pointer = shm.allocate(Layout::new::<u64>()).unwrap();
//! unsafe { shm_pointer.data_ptr.write(123) };
//!
//! // send shm_pointer to another process with [`ZeroCopyConnection`]
//! }
//!
//! fn process_two<Shm: SharedMemory<PoolAllocator>>() {
//! let shm_name = FileName::new(b"myShmName").unwrap();
//! let allocator_config = pool_allocator::Config {
//! // we want to allocate [`u64`]
//! bucket_layout: Layout::new::<u64>()
//! };
//! let shm = Shm::Builder::new(&shm_name).size(1024).open().unwrap();
//! let mut shm_pointer = shm.allocate(Layout::new::<u64>()).unwrap();
//! unsafe { shm_pointer.data_ptr.write(31) }
//!
//! // send shm_pointer to another process with [`ZeroCopyConnection`]
//! }
//! ```
use Debug;
use DeallocationError;
use TEMP_DIRECTORY;
pub use crate*;
use crate;
use FileName;
use Path;
/// The default suffix of every shared memory
pub const DEFAULT_SUFFIX: FileName = unsafe ;
/// The default prefix of every shared memory
pub const DEFAULT_PREFIX: FileName = unsafe ;
/// The default path hint for every shared memory
pub const DEFAULT_PATH_HINT: Path = TEMP_DIRECTORY;
/// Failure returned by [`SharedMemoryBuilder::create()`]
/// Failure returned by [`SharedMemoryBuilder::open()`]
/// Represents a pointer pointing to some [`SharedMemory`]. Consists of the actual data pointer and
/// an [`PointerOffset`] which can be used in combination with a
/// [`crate::zero_copy_connection::ZeroCopyConnection`]
/// Creates [`SharedMemory`].
/// Abstract concept of a memory shared between multiple processes. Can be created with the
/// [`SharedMemoryBuilder`].