tp::utils::AutoRingBuffer class

A ring buffer implementation with automatic allocation of memory and timestamp-based garbage collection.

An abstraction around the more involved tp::utils::GrowableRingBuffer. This one automatically allocates more buffers when running out of space.

Constructors, destructors, conversion operators

AutoRingBuffer(tp::Device* device, tp::BufferUsageMask usage, tp::MemoryPreference memoryPreference, tp::OverallocationBehavior overallocationBehavior = { 3.0f, 1.5f, 65536 }, const char* debugName = nullptr) explicit

Public functions

auto getAllocatedSize() const -> uint64_t
Returns the total size of all allocations in bytes.
auto getAllocationCount() const -> uint64_t
Returns the number of active allocations.
auto getRegionCount() const -> uint64_t
Returns the number of regions used so far.
auto getTotalSize() const -> uint64_t
Returns the total size of all regions in bytes.
void pop(uint64_t upToTimestamp)
Frees all of the allocations with a timestamp value less or equal to upToTimestamp, allowing their memory regions to be reused.
auto push(uint64_t allocationSize, uint64_t timestamp) -> tp::BufferView
Allocate a tp::BufferView with the given size.
auto trim() -> uint64_t
Attempts to free up unused memory regions. Returns the number of bytes freed.

Function documentation

tp::utils::AutoRingBuffer::AutoRingBuffer(tp::Device* device, tp::BufferUsageMask usage, tp::MemoryPreference memoryPreference, tp::OverallocationBehavior overallocationBehavior = { 3.0f, 1.5f, 65536 }, const char* debugName = nullptr) explicit

Parameters
device The Tephra device that new buffers should be allocated from.
usage The expected usage of the views allocated from this ring buffer.
memoryPreference The memory preference of the underlying memory.
overallocationBehavior The overallocation behavior to be applied when allocating new space.
debugName The debug name to use as a basis for the backing buffers.

tp::BufferView tp::utils::AutoRingBuffer::push(uint64_t allocationSize, uint64_t timestamp)

Allocate a tp::BufferView with the given size.

Parameters
allocationSize The size of the allocation to be made.
timestamp The timestamp determining the allocation lifetime. See tp::utils::AutoRingBuffer::pop.