join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::SharedMemory Class Reference

shared memory class. More...

#include <shared.hpp>

Inheritance diagram for join::SharedMemory:

Public Member Functions

 SharedMemory (const std::string &name, uint64_t size)
 create instance.
 
virtual ~SharedMemory ()
 destroy the instance.
 
virtual int open ()
 open or create the shared memory.
 
bool opened () const noexcept
 check if shared memory is opened.
 
virtual void close () noexcept
 close the shared memory.
 
virtual const void * get (uint64_t offset=0) const
 get a const pointer to the shared memory at a given offset.
 
virtual void * get (uint64_t offset=0)
 get a pointer to the shared memory at a given offset.
 
virtual uint64_t size () const noexcept
 get the size of the shared memory.
 

Static Public Member Functions

static int unlink (const std::string &name) noexcept
 destroy synchronization primitives and unlink the shared memory segment.
 

Protected Attributes

std::string _name
 shared memory name.
 
uint64_t _size = 0
 shared memory size.
 
void * _ptr = nullptr
 pointer to mapped shared memory.
 
int _fd = -1
 shared memory file descriptor.
 

Detailed Description

shared memory class.

Constructor & Destructor Documentation

◆ SharedMemory()

join::SharedMemory::SharedMemory ( const std::string & name,
uint64_t size )
inline

create instance.

Parameters
nameshared memory name.
sizeshared memory size.

◆ ~SharedMemory()

virtual join::SharedMemory::~SharedMemory ( )
inlinevirtual

destroy the instance.

Member Function Documentation

◆ close()

virtual void join::SharedMemory::close ( )
inlinevirtualnoexcept

close the shared memory.

Reimplemented in join::BasicQueue< Policy >.

◆ get() [1/2]

virtual void * join::SharedMemory::get ( uint64_t offset = 0)
inlinevirtual

get a pointer to the shared memory at a given offset.

Parameters
offsetbyte offset from the start of the shared memory.
Returns
pointer to the mapped memory at the specified offset, or nullptr if not opened.
Exceptions
std::out_of_rangeif offset is out of bounds.

Reimplemented in join::BasicQueue< Policy >.

◆ get() [2/2]

virtual const void * join::SharedMemory::get ( uint64_t offset = 0) const
inlinevirtual

get a const pointer to the shared memory at a given offset.

Parameters
offsetbyte offset from the start of the shared memory.
Returns
pointer to the mapped memory at the specified offset, or nullptr if not opened.
Exceptions
std::out_of_rangeif offset is out of bounds.

Reimplemented in join::BasicQueue< Policy >.

◆ open()

virtual int join::SharedMemory::open ( )
inlinevirtual

open or create the shared memory.

Returns
0 on success, -1 on failure.

Reimplemented in join::BasicQueue< Policy >.

◆ opened()

bool join::SharedMemory::opened ( ) const
inlinenoexcept

check if shared memory is opened.

Returns
true if opened, false otherwise.

◆ size()

virtual uint64_t join::SharedMemory::size ( ) const
inlinevirtualnoexcept

get the size of the shared memory.

Returns
shared memory size in bytes.

Reimplemented in join::BasicQueue< Policy >.

◆ unlink()

static int join::SharedMemory::unlink ( const std::string & name)
inlinestaticnoexcept

destroy synchronization primitives and unlink the shared memory segment.

Parameters
nameshared memory segment name.
Returns
0 on success, -1 on failure.

Member Data Documentation

◆ _fd

int join::SharedMemory::_fd = -1
protected

shared memory file descriptor.

◆ _name

std::string join::SharedMemory::_name
protected

shared memory name.

◆ _ptr

void* join::SharedMemory::_ptr = nullptr
protected

pointer to mapped shared memory.

◆ _size

uint64_t join::SharedMemory::_size = 0
protected

shared memory size.


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