CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | List of all members
CppCommon::SharedMemory Class Reference

Shared memory manager. More...

#include <shared_memory.h>

Public Member Functions

 SharedMemory (const std::string &name, size_t size)
 Create a new or open existing block of shared memory with a given name and size. More...
 
 SharedMemory (const SharedMemory &)=delete
 
 SharedMemory (SharedMemory &&shmem)=delete
 
 ~SharedMemory ()
 
SharedMemoryoperator= (const SharedMemory &)=delete
 
SharedMemoryoperator= (SharedMemory &&shmem)=delete
 
 operator bool () const
 Check if the shared memory block is valid. More...
 
const std::string & name () const noexcept
 Get the shared memory block name. More...
 
size_t size () const noexcept
 Get the shared memory block size. More...
 
void * ptr ()
 Get the shared memory block pointer. More...
 
const void * ptr () const
 Get the constant shared memory block pointer. More...
 
bool owner () const
 Get the shared memory owner flag (true if the new one was created, false if the existing one was opened) More...
 

Detailed Description

Shared memory manager.

Shared memory manager allows to create named memory buffers shared between multiple processes. This is one of the common ways to organize different kinds of IPC (inter-process communication).

Not thread-safe.

https://en.wikipedia.org/wiki/Shared_memory_(interprocess_communication)

Examples
system_shared_memory.cpp.

Definition at line 28 of file shared_memory.h.

Constructor & Destructor Documentation

◆ SharedMemory() [1/3]

CppCommon::SharedMemory::SharedMemory ( const std::string &  name,
size_t  size 
)
explicit

Create a new or open existing block of shared memory with a given name and size.

Parameters
name- Shared memory block name
size- Shared memory block size

Definition at line 187 of file shared_memory.cpp.

◆ SharedMemory() [2/3]

CppCommon::SharedMemory::SharedMemory ( const SharedMemory )
delete

◆ SharedMemory() [3/3]

CppCommon::SharedMemory::SharedMemory ( SharedMemory &&  shmem)
delete

◆ ~SharedMemory()

CppCommon::SharedMemory::~SharedMemory ( )

Definition at line 198 of file shared_memory.cpp.

Member Function Documentation

◆ name()

const std::string& CppCommon::SharedMemory::name ( ) const
inlinenoexcept

Get the shared memory block name.

Definition at line 48 of file shared_memory.h.

◆ operator bool()

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

Check if the shared memory block is valid.

Definition at line 45 of file shared_memory.h.

◆ operator=() [1/2]

SharedMemory& CppCommon::SharedMemory::operator= ( const SharedMemory )
delete

◆ operator=() [2/2]

SharedMemory& CppCommon::SharedMemory::operator= ( SharedMemory &&  shmem)
delete

◆ owner()

bool CppCommon::SharedMemory::owner ( ) const

Get the shared memory owner flag (true if the new one was created, false if the existing one was opened)

Examples
system_shared_memory.cpp.

Definition at line 206 of file shared_memory.cpp.

◆ ptr() [1/2]

void * CppCommon::SharedMemory::ptr ( )

Get the shared memory block pointer.

Examples
system_shared_memory.cpp.

Definition at line 204 of file shared_memory.cpp.

◆ ptr() [2/2]

const void * CppCommon::SharedMemory::ptr ( ) const

Get the constant shared memory block pointer.

Definition at line 205 of file shared_memory.cpp.

◆ size()

size_t CppCommon::SharedMemory::size ( ) const
inlinenoexcept

Get the shared memory block size.

Examples
system_shared_memory.cpp.

Definition at line 50 of file shared_memory.h.


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