![]() |
VSM C++ SDK
Vehicle Specific Modules SDK
|
Platform independent implementation of system-wide named shared memory used for interprocess communications. More...
#include <shared_memory.h>
Public Types | |
enum | Open_result { OPEN_RESULT_OK, OPEN_RESULT_CREATED, OPEN_RESULT_ERROR } |
Possible return codes from Open() call. | |
typedef std::shared_ptr < Shared_memory > | Ptr |
Pointer type. | |
typedef std::weak_ptr < Shared_memory > | Weak_ptr |
Pointer type. | |
Public Member Functions | |
Shared_memory () | |
Constructor should not be called explicitly. More... | |
virtual Open_result | Open (const std::string &name, const size_t size)=0 |
Open/create shared memory. More... | |
virtual void | Close ()=0 |
Closes previously opened memory. | |
virtual void * | Get () |
Returns the pointer to shared memory. More... | |
Static Public Member Functions | |
template<typename... Args> | |
static Ptr | Create (Args &&...args) |
Create an instance. More... | |
static bool | Delete (const std::string &name) |
Deletes the named memory. More... | |
static Ptr | Create () |
Creates Platform specific class instance. More... | |
Protected Attributes | |
void * | memory |
pointer to shared memory | |
Platform independent implementation of system-wide named shared memory used for interprocess communications.
Workflow: 1) Call Shared_memory::Create() to create class instance. 2) Call Shared_memory::Open() to open or create shared memory. 3) Call Shared_memory::Get() to Get the pointer to shared memory.
The pointer is valid until object is closed. Object is closed:
User must be aware of the following platform specific differences in shared memory semantics: Windows: 1) When the last handle to memory is closed the OS destroys the memory. (Note: OS closes all open handles on application termination/crash) 2) By default the memory is created in Session Kernel object namespace. 3) Shared memory cannot be explicitly deleted. Implemented via CreateFileMapping() and friends.
Linux: 1) Shared memory persists in the system until explicitly deleted or system restarted. 2) It is accessible from any session of its creator user. Implemented via shm_open() and friends.
|
inline |
Constructor should not be called explicitly.
Use Create() function to instantiate the object.
|
inlinestatic |
Create an instance.
|
static |
Creates Platform specific class instance.
This does not create the memory itself, you should call Open() to create the named memory.
|
static |
Deletes the named memory.
(Linux-only) Does not affect any opened memory with this name.
name | Shared memory name. |
|
inlinevirtual |
Returns the pointer to shared memory.
|
pure virtual |
Open/create shared memory.
Closes previously opened memory if any.
name | Name of memory object |
size | size in bytes. Will return error if size==0 |