Ocean
Ocean::SharedMemory Class Reference

This class implements a shared memory object allowing access to a shared buffer. More...

Public Member Functions

 SharedMemory ()=default
 Creates a new shared memory object. More...
 
 SharedMemory (const std::wstring &name, const size_t size)
 Creates a new shared memory object with specified buffer size. More...
 
 SharedMemory (const SharedMemory &sharedMemory)=delete
 Disabled copy constructor for a shared memory object. More...
 
 SharedMemory (SharedMemory &&sharedMemory) noexcept
 Move constructor for a shared memory object. More...
 
 ~SharedMemory ()
 Destructs a shared memory object. More...
 
const std::wstring & name () const
 Returns the system wide unique name of this shared memory. More...
 
size_t size () const
 Returns the size of the shared memory buffer in bytes. More...
 
bool resize (const size_t newSize)
 Resizes the shared memory buffer. More...
 
void flush ()
 Flushes the shared memory. More...
 
void release ()
 Releases the shared memory buffer. More...
 
const void * constdata () const
 Returns a pointer to the shared memory buffer. More...
 
void * data ()
 Returns a pointer to the shared memory buffer. More...
 
 operator bool () const
 Returns whether this shared memory object holds a valid shared buffer. More...
 
SharedMemoryoperator= (const SharedMemory &sharedMemory)=delete
 Disabled assign operator for shared memory objects. More...
 
SharedMemoryoperator= (SharedMemory &&sharedMemory) noexcept
 Move operator for shared memory objects. More...
 

Static Private Member Functions

static bool requestSharedMemory (const std::wstring &name, size_t &size, void *&handle, void *&data, bool *existedAlready=nullptr)
 Requests a shared memory buffer. More...
 

Private Attributes

std::wstring name_
 System wide unique memory name. More...
 
size_t size_ = 0
 Sized of the shared memory buffer in bytes. More...
 
void * data_ = nullptr
 Pointer to the shared memory. More...
 
void * handle_ = nullptr
 Shared memory handle. More...
 

Detailed Description

This class implements a shared memory object allowing access to a shared buffer.

See also
SharedLock.

Constructor & Destructor Documentation

◆ SharedMemory() [1/4]

Ocean::SharedMemory::SharedMemory ( )
default

Creates a new shared memory object.

◆ SharedMemory() [2/4]

Ocean::SharedMemory::SharedMemory ( const std::wstring &  name,
const size_t  size 
)

Creates a new shared memory object with specified buffer size.

Parameters
nameSystem wide unique name of the shared memory
sizeSize of the buffer in bytes

◆ SharedMemory() [3/4]

Ocean::SharedMemory::SharedMemory ( const SharedMemory sharedMemory)
delete

Disabled copy constructor for a shared memory object.

Parameters
sharedMemoryShared memory object to be copied

◆ SharedMemory() [4/4]

Ocean::SharedMemory::SharedMemory ( SharedMemory &&  sharedMemory)
noexcept

Move constructor for a shared memory object.

Parameters
sharedMemoryShared memory object to be copied

◆ ~SharedMemory()

Ocean::SharedMemory::~SharedMemory ( )

Destructs a shared memory object.

Member Function Documentation

◆ constdata()

const void * Ocean::SharedMemory::constdata ( ) const
inline

Returns a pointer to the shared memory buffer.

Returns
Memory buffer

◆ data()

void * Ocean::SharedMemory::data ( )
inline

Returns a pointer to the shared memory buffer.

Returns
Memory buffer

◆ flush()

void Ocean::SharedMemory::flush ( )

Flushes the shared memory.

◆ name()

const std::wstring & Ocean::SharedMemory::name ( ) const
inline

Returns the system wide unique name of this shared memory.

Returns
Shared memory name

◆ operator bool()

Ocean::SharedMemory::operator bool ( ) const
inlineexplicit

Returns whether this shared memory object holds a valid shared buffer.

Returns
True, if so

◆ operator=() [1/2]

SharedMemory& Ocean::SharedMemory::operator= ( const SharedMemory sharedMemory)
delete

Disabled assign operator for shared memory objects.

Parameters
sharedMemoryShared memory object to be assigned
Returns
Reference to this object

◆ operator=() [2/2]

SharedMemory& Ocean::SharedMemory::operator= ( SharedMemory &&  sharedMemory)
noexcept

Move operator for shared memory objects.

Parameters
sharedMemoryShared memory object to be moved
Returns
Reference to this object

◆ release()

void Ocean::SharedMemory::release ( )

Releases the shared memory buffer.

◆ requestSharedMemory()

static bool Ocean::SharedMemory::requestSharedMemory ( const std::wstring &  name,
size_t &  size,
void *&  handle,
void *&  data,
bool *  existedAlready = nullptr 
)
staticprivate

Requests a shared memory buffer.

Parameters
nameUnique system wide memory name
sizeSize of the requested memory and finally the resulting size of the created memory (or already existing memory)
handleResulting memory handle
dataResulting buffer pointer
existedAlreadyOptional resulting whether the buffer existed already
Returns
True, if succeeded

◆ resize()

bool Ocean::SharedMemory::resize ( const size_t  newSize)

Resizes the shared memory buffer.

Parameters
newSizeNew size of the shared buffer in bytes
Returns
True, if succeeded

◆ size()

size_t Ocean::SharedMemory::size ( ) const
inline

Returns the size of the shared memory buffer in bytes.

Returns
Buffer size

Field Documentation

◆ data_

void* Ocean::SharedMemory::data_ = nullptr
private

Pointer to the shared memory.

◆ handle_

void* Ocean::SharedMemory::handle_ = nullptr
private

Shared memory handle.

◆ name_

std::wstring Ocean::SharedMemory::name_
private

System wide unique memory name.

◆ size_

size_t Ocean::SharedMemory::size_ = 0
private

Sized of the shared memory buffer in bytes.


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