POSIX Shared Memory Data Structures 1.0
High-performance lock-free data structures for inter-process communication
|
Fixed-size array in shared memory with zero-overhead access. More...
#include <shm_array.h>
Public Types | |
STL Type Definitions | |
using | value_type = T |
Element type. | |
using | size_type = size_t |
Size type. | |
using | difference_type = std::ptrdiff_t |
Iterator difference. | |
using | reference = T & |
Reference type. | |
using | const_reference = const T & |
Const reference. | |
using | pointer = T * |
Pointer type. | |
using | const_pointer = const T * |
Const pointer. | |
using | iterator = T * |
Iterator type (raw pointer) | |
using | const_iterator = const T * |
Const iterator. | |
using | reverse_iterator = std::reverse_iterator< iterator > |
Reverse iterator. | |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Const reverse. | |
Public Member Functions | |
template<typename ShmType > | |
shm_array (ShmType &shared_mem, std::string_view name, size_t count=0) | |
Create new array or attach to existing array by name. | |
void | initialize (std::string_view name, size_t count=0) |
Internal initialization helper. | |
T & | at (size_t pos) |
Bounds-checked element access. | |
const T & | at (size_t pos) const |
Const version of at() | |
T & | front () |
Access first element. | |
const T & | front () const |
Access first element (const) | |
T & | back () |
Access last element. | |
const T & | back () const |
Access last element (const) | |
bool | empty () const noexcept |
Check if array is empty. | |
size_t | size () const noexcept |
Get number of elements. | |
void | fill (const T &value) |
Fill array with value. | |
std::span< T > | as_span () noexcept |
Convert to std::span for modern C++ usage. | |
std::span< const T > | as_span () const noexcept |
Convert to const span. | |
size_type | max_size () const noexcept |
Get maximum size (same as size() for fixed arrays) | |
pointer | data () noexcept |
Get pointer to underlying data. | |
const_pointer | data () const noexcept |
Get const pointer to underlying data. | |
std::string_view | name () const noexcept |
Get array name from metadata table. | |
Iterator Support | |
iterator | begin () noexcept |
Get iterator to beginning. | |
iterator | end () noexcept |
Get iterator to end. | |
const_iterator | begin () const noexcept |
Get const iterator to beginning. | |
const_iterator | end () const noexcept |
Get const iterator to end. | |
const_iterator | cbegin () const noexcept |
Get const iterator to beginning (explicit) | |
const_iterator | cend () const noexcept |
Get const iterator to end (explicit) | |
Reverse Iterator Support | |
reverse_iterator | rbegin () noexcept |
Get reverse iterator to beginning. | |
reverse_iterator | rend () noexcept |
Get reverse iterator to end. | |
const_reverse_iterator | rbegin () const noexcept |
Get const reverse iterator to beginning. | |
const_reverse_iterator | rend () const noexcept |
Get const reverse iterator to end. | |
const_reverse_iterator | crbegin () const noexcept |
Get const reverse iterator to beginning (explicit) | |
const_reverse_iterator | crend () const noexcept |
Get const reverse iterator to end (explicit) | |
![]() | |
shm_span (ShmType &shm, size_t off, size_t count) | |
T * | data () |
const T * | data () const |
size_t | size () const |
T & | operator[] (size_t index) |
const T & | operator[] (size_t index) const |
Additional Inherited Members | |
![]() | |
ShmType & | shm |
size_t | offset |
size_t | num_elem |
Fixed-size array in shared memory with zero-overhead access.
Provides a fully STL-compliant array interface for shared memory. Key features:
Memory layout:
T | Element type (must be trivially copyable for shared memory) |
TableType | Metadata table type (default: shm_table) |
Definition at line 62 of file shm_array.h.
Const iterator.
Definition at line 277 of file shm_array.h.
Const pointer.
Definition at line 275 of file shm_array.h.
Const reference.
Definition at line 273 of file shm_array.h.
using shm_array< T, TableType >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Const reverse.
Definition at line 279 of file shm_array.h.
Iterator difference.
Definition at line 271 of file shm_array.h.
Iterator type (raw pointer)
Definition at line 276 of file shm_array.h.
Pointer type.
Definition at line 274 of file shm_array.h.
Reference type.
Definition at line 272 of file shm_array.h.
Reverse iterator.
Definition at line 278 of file shm_array.h.
Size type.
Definition at line 270 of file shm_array.h.
Element type.
Definition at line 269 of file shm_array.h.
|
inline |
Create new array or attach to existing array by name.
ShmType | Type of shared memory (must have matching TableType) |
shared_mem | Shared memory segment to allocate from |
name | Unique identifier for the array (max TableType::MAX_NAME_SIZE chars) |
count | Number of elements (0 = attach to existing) |
std::runtime_error | if creation fails (insufficient space) |
std::runtime_error | if name not found and count=0 |
std::runtime_error | if existing array has different size |
Definition at line 97 of file shm_array.h.
References shm_array< T, TableType >::initialize(), and shm_array< T, TableType >::name().
Convert to const span.
Definition at line 262 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Convert to std::span for modern C++ usage.
Definition at line 256 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Bounds-checked element access.
pos | Index to access |
std::out_of_range | if pos >= size() |
Definition at line 179 of file shm_array.h.
References shm_span< T, ShmType >::num_elem.
Const version of at()
Definition at line 190 of file shm_array.h.
References shm_span< T, ShmType >::num_elem.
Access last element.
Definition at line 210 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Access last element (const)
Definition at line 213 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
|
inlinenoexcept |
Get const iterator to beginning.
Definition at line 292 of file shm_array.h.
References shm_array< T, TableType >::data().
Get iterator to beginning.
Definition at line 286 of file shm_array.h.
References shm_array< T, TableType >::data().
Referenced by shm_array< T, TableType >::cbegin(), main(), shm_array< T, TableType >::rend(), and shm_array< T, TableType >::rend().
|
inlinenoexcept |
Get const iterator to beginning (explicit)
Definition at line 298 of file shm_array.h.
References shm_array< T, TableType >::begin().
|
inlinenoexcept |
Get const iterator to end (explicit)
Definition at line 301 of file shm_array.h.
References shm_array< T, TableType >::end().
|
inlinenoexcept |
Get const reverse iterator to beginning (explicit)
Definition at line 320 of file shm_array.h.
References shm_array< T, TableType >::rbegin().
|
inlinenoexcept |
Get const reverse iterator to end (explicit)
Definition at line 323 of file shm_array.h.
References shm_array< T, TableType >::rend().
|
inlinenoexcept |
Get const pointer to underlying data.
Definition at line 336 of file shm_array.h.
References shm_array< T, TableType >::data().
Get pointer to underlying data.
Definition at line 333 of file shm_array.h.
References shm_array< T, TableType >::data().
Referenced by shm_array< T, TableType >::as_span(), shm_array< T, TableType >::as_span(), shm_array< T, TableType >::back(), shm_array< T, TableType >::back(), shm_array< T, TableType >::begin(), shm_array< T, TableType >::begin(), calculate_kinetic_energy_simd(), shm_array< T, TableType >::data(), shm_array< T, TableType >::data(), shm_simd::SimdArray< TableType >::dot(), shm_array< T, TableType >::end(), shm_array< T, TableType >::end(), shm_array< T, TableType >::fill(), shm_array< T, TableType >::front(), shm_array< T, TableType >::front(), main(), shm_simd::SimdArray< TableType >::max(), shm_simd::SimdArray< TableType >::min(), shm_simd::SimdArray< TableType >::scale(), and shm_simd::SimdArray< TableType >::sum().
Check if array is empty.
Definition at line 217 of file shm_array.h.
References shm_span< T, ShmType >::num_elem.
|
inlinenoexcept |
Get const iterator to end.
Definition at line 295 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Get iterator to end.
Definition at line 289 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Referenced by shm_array< T, TableType >::cend(), main(), shm_array< T, TableType >::rbegin(), and shm_array< T, TableType >::rbegin().
Fill array with value.
value | Value to fill with |
Definition at line 238 of file shm_array.h.
References shm_array< T, TableType >::data(), and shm_span< T, ShmType >::num_elem.
Access first element.
Definition at line 202 of file shm_array.h.
References shm_array< T, TableType >::data().
Access first element (const)
Definition at line 205 of file shm_array.h.
References shm_array< T, TableType >::data().
Internal initialization helper.
Definition at line 114 of file shm_array.h.
References shm_array< T, TableType >::name(), shm_span< T, ShmType >::num_elem, shm_span< T, ShmType >::offset, and shm_span< T, ShmType >::shm.
Referenced by shm_array< T, TableType >::shm_array().
Get maximum size (same as size() for fixed arrays)
Definition at line 328 of file shm_array.h.
References shm_span< T, ShmType >::num_elem.
Get array name from metadata table.
Definition at line 353 of file shm_array.h.
Referenced by example_large_simulation(), example_minimal_overhead(), shm_array< T, TableType >::initialize(), and shm_array< T, TableType >::shm_array().
|
inlinenoexcept |
Get const reverse iterator to beginning.
Definition at line 314 of file shm_array.h.
References shm_array< T, TableType >::end().
|
inlinenoexcept |
Get reverse iterator to beginning.
Definition at line 308 of file shm_array.h.
References shm_array< T, TableType >::end().
Referenced by shm_array< T, TableType >::crbegin().
|
inlinenoexcept |
Get const reverse iterator to end.
Definition at line 317 of file shm_array.h.
References shm_array< T, TableType >::begin().
|
inlinenoexcept |
Get reverse iterator to end.
Definition at line 311 of file shm_array.h.
References shm_array< T, TableType >::begin().
Referenced by shm_array< T, TableType >::crend().
Get number of elements.
Definition at line 221 of file shm_array.h.
References shm_span< T, ShmType >::num_elem.
Referenced by shm_simd::SimdArray< TableType >::dot(), example_custom_config(), example_minimal_overhead(), main(), shm_simd::SimdArray< TableType >::max(), shm_simd::SimdArray< TableType >::min(), shm_simd::SimdArray< TableType >::scale(), and shm_simd::SimdArray< TableType >::sum().