Cheetah Software
1.0
|
#include <SharedMemory.h>
Public Member Functions | |
SharedMemoryObject ()=default | |
bool | createNew (const std::string &name, bool allowOverwrite=false) |
void | attach (const std::string &name) |
void | closeNew () |
void | detach () |
T * | get () |
T & | operator() () |
Private Attributes | |
T * | _data = nullptr |
std::string | _name |
size_t | _size |
int | _fd |
A container class for an object which is stored in shared memory. This object can then be viewed in multiple processes or programs. Note that there is significant overhead when creating a shared memory object, so it is recommended that two programs that communicate should have one single large SharedMemoryObject instead of many small ones.
A name string is used to identify shared objects across different programs
Before a shared memory object can be used, you must either allocate new memory, or connect it to an existing shared memory object.
Creating/deleting the memory can be done with createNew/closeNew. Viewing an existing object allocated with createNew can be done with attach/detach
For an example, see test_sharedMemory.cpp
Definition at line 112 of file SharedMemory.h.
|
default |
|
inline |
Attach to an existing shared memory object.
Definition at line 191 of file SharedMemory.h.
|
inline |
Free memory associated with the current open shared memory object. The object could have been opened with either attach or createNew. After calling this, no process can use this shared object
Definition at line 241 of file SharedMemory.h.
|
inline |
Allocate memory for the shared memory object and attach to it. If allowOverwrite is true, and there's already an object with this name, the old object is overwritten Note that if this happens, the object may be initialized in a very weird state.
Otherwise, if an object with the name already exists, throws a std::runtime_error
Definition at line 125 of file SharedMemory.h.
|
inline |
Close this view of the currently opened shared memory object. The object can be opened with either attach or createNew. After calling this, this process can no longer use this shared object, but other processes still can.
Definition at line 277 of file SharedMemory.h.
|
inline |
Get the shared memory object.
Definition at line 303 of file SharedMemory.h.
|
inline |
Get the shared memory object.
Definition at line 311 of file SharedMemory.h.
|
private |
Definition at line 317 of file SharedMemory.h.
|
private |
Definition at line 320 of file SharedMemory.h.
|
private |
Definition at line 318 of file SharedMemory.h.
|
private |
Definition at line 319 of file SharedMemory.h.