POSIX Shared Memory Data Structures 1.0
High-performance lock-free data structures for inter-process communication
|
Lock-free ring buffer for high-throughput streaming data. More...
#include <shm_ring_buffer.h>
Public Types | |
using | value_type = T |
using | size_type = size_t |
Public Member Functions | |
template<typename ShmType > | |
shm_ring_buffer (ShmType &shm, std::string_view name, size_t capacity=0) | |
bool | push (const T &value) noexcept |
Push a single element. | |
size_t | push_bulk (std::span< const T > values) noexcept |
Push multiple elements efficiently. | |
std::optional< T > | pop () noexcept |
Pop a single element. | |
size_t | pop_bulk (std::span< T > values) noexcept |
Pop multiple elements efficiently. | |
size_t | peek_bulk (size_t offset, std::span< T > values) const noexcept |
Peek at elements without consuming them. | |
size_t | get_last_n (size_t n, std::span< T > values) const noexcept |
Get the last N elements (most recent) Useful for getting trailing sensor data. | |
void | skip (size_t count) noexcept |
Skip elements without reading them. | |
void | clear () noexcept |
Clear the buffer (reset read/write positions) | |
size_t | capacity () const noexcept |
size_t | size () const noexcept |
bool | empty () const noexcept |
bool | full () const noexcept |
size_t | available_space () const noexcept |
uint64_t | total_written () const noexcept |
Get total elements written (useful for monitoring data rate) | |
uint64_t | total_read () const noexcept |
std::string_view | name () const noexcept |
void | push_overwrite (const T &value) noexcept |
Force overwrite when full (converts to circular overwrite mode) Useful for continuous sensor streams where latest data is most important. | |
Lock-free ring buffer for high-throughput streaming data.
Optimized for bulk operations and sensor data streams. Supports multiple readers that can read without consuming.
Better than queue when you need:
T | Element type |
TableType | Metadata table type |
Definition at line 24 of file shm_ring_buffer.h.
using shm_ring_buffer< T, TableType >::size_type = size_t |
Definition at line 45 of file shm_ring_buffer.h.
using shm_ring_buffer< T, TableType >::value_type = T |
Definition at line 44 of file shm_ring_buffer.h.
|
inline |
Definition at line 48 of file shm_ring_buffer.h.
References shm_ring_buffer< T, TableType >::capacity(), and shm_ring_buffer< T, TableType >::name().
|
inlinenoexcept |
Definition at line 250 of file shm_ring_buffer.h.
References shm_ring_buffer< T, TableType >::capacity(), and shm_ring_buffer< T, TableType >::size().
|
inlinenoexcept |
Definition at line 232 of file shm_ring_buffer.h.
Referenced by shm_ring_buffer< T, TableType >::available_space(), shm_ring_buffer< T, TableType >::full(), and shm_ring_buffer< T, TableType >::shm_ring_buffer().
|
inlinenoexcept |
Clear the buffer (reset read/write positions)
Definition at line 226 of file shm_ring_buffer.h.
|
inlinenoexcept |
Definition at line 242 of file shm_ring_buffer.h.
References shm_ring_buffer< T, TableType >::size().
|
inlinenoexcept |
Definition at line 246 of file shm_ring_buffer.h.
References shm_ring_buffer< T, TableType >::capacity(), and shm_ring_buffer< T, TableType >::size().
|
inlinenoexcept |
Get the last N elements (most recent) Useful for getting trailing sensor data.
Definition at line 195 of file shm_ring_buffer.h.
Referenced by sensor_streaming_example().
|
inlinenoexcept |
Definition at line 265 of file shm_ring_buffer.h.
Referenced by shm_ring_buffer< T, TableType >::shm_ring_buffer().
|
inlinenoexcept |
Peek at elements without consuming them.
offset | How many elements to skip from the front | |
[out] | values | Buffer to store peeked elements |
Definition at line 173 of file shm_ring_buffer.h.
|
inlinenoexcept |
Pop a single element.
Definition at line 134 of file shm_ring_buffer.h.
|
inlinenoexcept |
Pop multiple elements efficiently.
[out] | values | Buffer to store popped elements |
Definition at line 152 of file shm_ring_buffer.h.
Referenced by sensor_streaming_example().
|
inlinenoexcept |
Push a single element.
Definition at line 98 of file shm_ring_buffer.h.
Referenced by sensor_streaming_example().
|
inlinenoexcept |
Push multiple elements efficiently.
Definition at line 115 of file shm_ring_buffer.h.
|
inlinenoexcept |
Force overwrite when full (converts to circular overwrite mode) Useful for continuous sensor streams where latest data is most important.
Definition at line 273 of file shm_ring_buffer.h.
|
inlinenoexcept |
Definition at line 236 of file shm_ring_buffer.h.
Referenced by shm_ring_buffer< T, TableType >::available_space(), shm_ring_buffer< T, TableType >::empty(), shm_ring_buffer< T, TableType >::full(), and sensor_streaming_example().
|
inlinenoexcept |
Skip elements without reading them.
Definition at line 213 of file shm_ring_buffer.h.
|
inlinenoexcept |
Definition at line 261 of file shm_ring_buffer.h.
|
inlinenoexcept |
Get total elements written (useful for monitoring data rate)
Definition at line 257 of file shm_ring_buffer.h.
Referenced by sensor_streaming_example().