Public Member Functions | List of all members
MSharedMemoryObject< T > Class Template Reference

A shared memory object that uses the Boost interprocess library. More...

#include <MSharedMemoryObject.hpp>

Public Member Functions

template<typename ... P>
 MSharedMemoryObject (const P &... params)
 Create a shared memory object of type T with the supplied input arguments. More...
 
template<typename ... P>
 MSharedMemoryObject (CreateOnlySelector, const std::string &name, const P &... params)
 Create a shared memory object of type T with the supplied input arguments. More...
 
template<typename ... P>
 MSharedMemoryObject (OpenOrCreateSelector, const std::string &name, const P &... params)
 Create or open a shared memory object of type T with the supplied input arguments. More...
 
 MSharedMemoryObject (OpenOnlySelector, const std::string &name)
 Open a shared memory object of type T. More...
 
 MSharedMemoryObject (OpenReadOnlySelector, const std::string &name)
 Open read-only a shared memory object of type T. More...
 
 MSharedMemoryObject (MSharedMemoryObject &&rhs) noexcept
 Create a shared memory object by moving from a previously created one. More...
 
 ~MSharedMemoryObject ()
 Destroy the shared memory object. More...
 
T & operator* ()
 Get a reference to the shared memory object. More...
 
const T & operator* () const
 Get a const reference to the shared memory object. More...
 
T * operator-> ()
 Get the shared memory object pointer. More...
 
const T * operator-> () const
 Get the shared memory object pointer. More...
 
MSharedMemoryObjectoperator= (MSharedMemoryObject &&rhs) noexcept
 Assign a shared memory object by moving from a previously created one. More...
 

Detailed Description

template<typename T>
class Balau::Interprocess::MSharedMemoryObject< T >

A shared memory object that uses the Boost interprocess library.

This version uses managed shared memory which does not require a call to remap in the child process after forking.

Note that shared memory is typically allocated in 4k pages, and a whole page will be allocated even if the object size is a single byte.

Note that the management state requires 512 bytes of the 4k page, so the maximum object size is 3.5KB before a second page is used.

This template class encapsulates the calls to the Boost interprocess library in order to create a shared memory object, and provides a simple API to construct/open and use the object.

Note that when using this class, the type T must have a POD type structure. If the type contains pointers, the objects pointed to will not share and consequently your application will be defective.

Constructor & Destructor Documentation

◆ MSharedMemoryObject() [1/6]

MSharedMemoryObject ( const P &...  params)
inlineexplicit

Create a shared memory object of type T with the supplied input arguments.

The name prefix is automatically generated.

◆ MSharedMemoryObject() [2/6]

MSharedMemoryObject ( CreateOnlySelector  ,
const std::string &  name,
const P &...  params 
)
inline

Create a shared memory object of type T with the supplied input arguments.

The specified name prefix is used.

◆ MSharedMemoryObject() [3/6]

MSharedMemoryObject ( OpenOrCreateSelector  ,
const std::string &  name,
const P &...  params 
)
inline

Create or open a shared memory object of type T with the supplied input arguments.

The specified name prefix is used.

If the object already exists, it is opened and the supplied parameters are ignored.

◆ MSharedMemoryObject() [4/6]

MSharedMemoryObject ( OpenOnlySelector  ,
const std::string &  name 
)
inline

Open a shared memory object of type T.

The specified name prefix is used.

Exceptions
NotFoundExceptionif no such shared memory object exists

◆ MSharedMemoryObject() [5/6]

MSharedMemoryObject ( OpenReadOnlySelector  ,
const std::string &  name 
)
inline

Open read-only a shared memory object of type T.

The specified name prefix is used.

Exceptions
NotFoundExceptionif no such shared memory object exists

◆ ~MSharedMemoryObject()

~MSharedMemoryObject ( )
inline

Destroy the shared memory object.

◆ MSharedMemoryObject() [6/6]

MSharedMemoryObject ( MSharedMemoryObject< T > &&  rhs)
inlinenoexcept

Create a shared memory object by moving from a previously created one.

Member Function Documentation

◆ operator*() [1/2]

T& operator* ( )
inline

Get a reference to the shared memory object.

◆ operator*() [2/2]

const T& operator* ( ) const
inline

Get a const reference to the shared memory object.

◆ operator->() [1/2]

T* operator-> ( )
inline

Get the shared memory object pointer.

◆ operator->() [2/2]

const T* operator-> ( ) const
inline

Get the shared memory object pointer.

◆ operator=()

MSharedMemoryObject& operator= ( MSharedMemoryObject< T > &&  rhs)
inlinenoexcept

Assign a shared memory object by moving from a previously created one.


The documentation for this class was generated from the following file: