POSIX Shared Memory Data Structures 1.0
High-performance lock-free data structures for inter-process communication
Loading...
Searching...
No Matches
shm_table_impl< MaxNameSize, MaxEntries > Class Template Reference

Metadata table for managing shared memory data structures. More...

#include <shm_table.h>

Classes

struct  entry
 

Public Member Functions

 shm_table_impl ()=default
 
bool add (const char *name, size_t offset, size_t size, size_t elem_size=0, size_t num_elem=0)
 Add a new entry to the table.
 
bool add (std::string_view name, size_t offset, size_t size, size_t elem_size=0, size_t num_elem=0)
 
bool erase (const char *name)
 
bool erase (std::string_view name)
 
entryfind (const char *name)
 Find an entry by name.
 
const entryfind (const char *name) const
 
entryfind (std::string_view name)
 
const entryfind (std::string_view name) const
 
size_t get_total_allocated_size () const
 Get total allocated size (excluding the table itself)
 
size_t get_entry_count () const
 Get number of active entries.
 
void clear ()
 Clear all entries (for initialization)
 

Static Public Member Functions

static constexpr size_t size_bytes ()
 Get the actual size of this table in bytes.
 

Static Public Attributes

static constexpr size_t MAX_NAME_SIZE = MaxNameSize
 
static constexpr size_t MAX_ENTRIES = MaxEntries
 

Detailed Description

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
class shm_table_impl< MaxNameSize, MaxEntries >

Metadata table for managing shared memory data structures.

Stored at the beginning of shared memory segment to allow dynamic discovery and management of data structures.

Template Parameters
MaxNameSizeMaximum size for entry names (default 32)
MaxEntriesMaximum number of entries in the table (default 64)

Definition at line 20 of file shm_table.h.

Constructor & Destructor Documentation

◆ shm_table_impl()

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
shm_table_impl< MaxNameSize, MaxEntries >::shm_table_impl ( )
default

Member Function Documentation

◆ add() [1/2]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
bool shm_table_impl< MaxNameSize, MaxEntries >::add ( const char *  name,
size_t  offset,
size_t  size,
size_t  elem_size = 0,
size_t  num_elem = 0 
)
inline

Add a new entry to the table.

Parameters
nameName of the resource that resides in shared memory.
offsetOffset of the resource in shared memory.
sizeTotal size of the resource in bytes.
elem_sizeSize of each element (for arrays/queues).
num_elemNumber of elements.
Returns
true if added successfully, false if name exists or table full.

Definition at line 53 of file shm_table.h.

References shm_table_impl< MaxNameSize, MaxEntries >::find(), shm_table_impl< MaxNameSize, MaxEntries >::MAX_ENTRIES, and shm_table_impl< MaxNameSize, MaxEntries >::MAX_NAME_SIZE.

Referenced by shm_table_impl< MaxNameSize, MaxEntries >::add().

◆ add() [2/2]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
bool shm_table_impl< MaxNameSize, MaxEntries >::add ( std::string_view  name,
size_t  offset,
size_t  size,
size_t  elem_size = 0,
size_t  num_elem = 0 
)
inline

◆ clear()

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
void shm_table_impl< MaxNameSize, MaxEntries >::clear ( )
inline

Clear all entries (for initialization)

Definition at line 185 of file shm_table.h.

References shm_table_impl< MaxNameSize, MaxEntries >::entry::active, and shm_table_impl< MaxNameSize, MaxEntries >::MAX_ENTRIES.

◆ erase() [1/2]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
bool shm_table_impl< MaxNameSize, MaxEntries >::erase ( const char *  name)
inline

◆ erase() [2/2]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
bool shm_table_impl< MaxNameSize, MaxEntries >::erase ( std::string_view  name)
inline

◆ find() [1/4]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
entry * shm_table_impl< MaxNameSize, MaxEntries >::find ( const char *  name)
inline

Find an entry by name.

Returns
Pointer to entry if found, nullptr otherwise

Definition at line 118 of file shm_table.h.

References shm_table_impl< MaxNameSize, MaxEntries >::MAX_ENTRIES.

Referenced by shm_table_impl< MaxNameSize, MaxEntries >::add(), shm_table_impl< MaxNameSize, MaxEntries >::find(), and shm_table_impl< MaxNameSize, MaxEntries >::find().

◆ find() [2/4]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
const entry * shm_table_impl< MaxNameSize, MaxEntries >::find ( const char *  name) const
inline

◆ find() [3/4]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
entry * shm_table_impl< MaxNameSize, MaxEntries >::find ( std::string_view  name)
inline

◆ find() [4/4]

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
const entry * shm_table_impl< MaxNameSize, MaxEntries >::find ( std::string_view  name) const
inline

◆ get_entry_count()

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
size_t shm_table_impl< MaxNameSize, MaxEntries >::get_entry_count ( ) const
inline

Get number of active entries.

Definition at line 171 of file shm_table.h.

References shm_table_impl< MaxNameSize, MaxEntries >::MAX_ENTRIES.

◆ get_total_allocated_size()

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
size_t shm_table_impl< MaxNameSize, MaxEntries >::get_total_allocated_size ( ) const
inline

Get total allocated size (excluding the table itself)

Definition at line 163 of file shm_table.h.

◆ size_bytes()

template<size_t MaxNameSize = 32, size_t MaxEntries = 64>
static constexpr size_t shm_table_impl< MaxNameSize, MaxEntries >::size_bytes ( )
inlinestaticconstexpr

Get the actual size of this table in bytes.

Definition at line 197 of file shm_table.h.

Member Data Documentation

◆ MAX_ENTRIES

◆ MAX_NAME_SIZE


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