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

◆ resize()

template<typename T , typename StoragePolicy , typename ConcurrencyPolicy = SingleThreadedPolicy, typename AccessPattern = QueueAccess>
void MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::resize ( size_t  new_capacity)
inline

Resize buffer capacity (DynamicStorage only)

Parameters
new_capacityNew maximum element count

Preserves existing data ordered by AccessPattern. Not Real-time Safe: May trigger heap allocation.

Definition at line 986 of file RingBuffer.hpp.

988 {
989 if (new_capacity == m_storage.capacity())
990 return;
991
992 auto current_data = snapshot();
993
994 m_storage.resize(new_capacity);
995 m_linearized.resize(new_capacity);
996
997 m_state.write_index = 0;
998 m_state.read_index = 0;
999
1000 size_t to_copy = std::min(current_data.size(), new_capacity);
1001 for (size_t i = 0; i < to_copy; ++i) {
1002 m_storage.buffer[i] = current_data[i];
1003 }
1004
1005 if constexpr (AccessPattern::push_front) {
1006 m_state.write_index = (to_copy > 0) ? to_copy - 1 : 0;
1007 } else {
1008 m_state.write_index = to_copy;
1009 }
1010 }
std::vector< T > snapshot() const
Thread-safe snapshot of buffer contents.

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

+ Here is the call graph for this function: