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

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

#include <USharedMemoryObject.hpp>

Public Member Functions

template<typename ... P>
 USharedMemoryObject (const P &... params)
 Create a shared memory object of type T with the supplied input arguments. More...
 
template<typename ... P>
 USharedMemoryObject (boost::interprocess::create_only_t, std::string name_, const P &... params)
 Create a shared memory object of type T with the supplied input arguments. More...
 
template<typename ... P>
 USharedMemoryObject (boost::interprocess::open_or_create_t, std::string name_, const P &... params)
 Create or open a shared memory object of type T with the supplied input arguments. More...
 
 USharedMemoryObject (boost::interprocess::open_only_t, std::string name_)
 Open a shared memory object of type T and with the specified name. More...
 
 USharedMemoryObject (boost::interprocess::open_read_only_t, std::string name_)
 Open read-only a shared memory object of type T and with the specified name. More...
 
 USharedMemoryObject (USharedMemoryObject &&rhs) noexcept
 Create a shared memory object by moving from a previously created one. 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...
 
USharedMemoryObjectoperator= (USharedMemoryObject &&rhs) noexcept
 Assign a shared memory object by moving from a previously created one. More...
 

Detailed Description

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

A shared memory object that uses the Boost interprocess library.

This version uses unmanaged shared memory which requires 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.

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

◆ USharedMemoryObject() [1/6]

USharedMemoryObject ( const P &...  params)
inlineexplicit

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

An automatically generated name is used.

◆ USharedMemoryObject() [2/6]

USharedMemoryObject ( boost::interprocess::create_only_t  ,
std::string  name_,
const P &...  params 
)
inline

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

The specified name is used.

◆ USharedMemoryObject() [3/6]

USharedMemoryObject ( boost::interprocess::open_or_create_t  ,
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 is used.

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

◆ USharedMemoryObject() [4/6]

USharedMemoryObject ( boost::interprocess::open_only_t  ,
std::string  name_ 
)
inline

Open a shared memory object of type T and with the specified name.

◆ USharedMemoryObject() [5/6]

USharedMemoryObject ( boost::interprocess::open_read_only_t  ,
std::string  name_ 
)
inline

Open read-only a shared memory object of type T and with the specified name.

◆ USharedMemoryObject() [6/6]

USharedMemoryObject ( USharedMemoryObject< 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=()

USharedMemoryObject& operator= ( USharedMemoryObject< 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: