MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ snapshot()

template<typename T , typename StoragePolicy , typename ConcurrencyPolicy = SingleThreadedPolicy, typename AccessPattern = QueueAccess>
std::vector< T > MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::snapshot ( ) const
inline

Thread-safe snapshot of buffer contents.

Returns
Vector copy ordered by AccessPattern

Safe for lock-free contexts but allocates memory. For LockFreePolicy, provides consistent view despite concurrent access.

Not Real-time Safe: Allocates std::vector.

// Lock-free queue
auto events = queue.snapshot(); // Safe despite concurrent push
for (const auto& event : events) {
write_to_disk(event); // Can block safely
}
std::vector< T > snapshot() const
Thread-safe snapshot of buffer contents.
Policy-driven unified circular buffer implementation.

Definition at line 913 of file RingBuffer.hpp.

914 {
915 std::vector<T> result;
916
917 if constexpr (is_lock_free) {
918 const size_t cap = m_storage.capacity();
919 auto read = m_state.read_index.load(std::memory_order_acquire);
920 auto write = m_state.write_index.load(std::memory_order_acquire);
921
922 result.reserve(cap);
923 while (read != write) {
924 result.push_back(m_storage.buffer[read]);
925 read = State::increment(read, cap);
926 }
927 } else {
928 auto view = linearized_view();
929 result.assign(view.begin(), view.end());
930 }
931
932 return result;
933 }
std::span< T > linearized_view() const
Get linearized view of buffer contents.
static constexpr bool is_lock_free

References MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::is_lock_free, MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::linearized_view(), MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::m_state, and MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::m_storage.

Referenced by MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: