Filament::Capture::RingBuffer(T)
Inherits Reference < Object
A generic circular ring buffer that supports concurrent single-producer and single-consumer access via atomic index operations.
buffer = Filament::Capture::RingBuffer(Int32).new(1024)
buffer.push(42)
value = buffer.pop # => 42
When the buffer is full, push overwrites the oldest item and
increments the drop counter. When empty, pop returns nil.
Constructors
Creates a new ring buffer with the specified capacity. The capacity must be at least 1 (and ideally a power of 2 for performance, but we don't enforce that since modulo works fine for our scale).
Instance methods
Removes all items from the buffer and resets the statistics. Not safe to call while producer/consumer are active.
Iterates over all items currently in the buffer without removing them. This is a snapshot operation - items pushed during iteration may or may not be seen, and items popped during iteration may cause inconsistencies. Best used when the producer is paused.
NOTE: This copies the items to avoid races. For large buffers with large items, this can be expensive.
Pops the oldest item from the buffer. Returns nil if the buffer is empty.
This method is designed to be called from a single consumer fiber. It never blocks.
Tries to pop up to max items at once, returning them in an array.
This is more efficient than calling pop in a loop because we only
pay the atomic read overhead once for the count check.
Pushes an item into the buffer. If the buffer is full, the oldest item is silently overwritten and counted as a drop.
This method is designed to be called from a single producer fiber. It never blocks, which is critical for the capture path.
Returns a snapshot of the current buffer statistics. This is a point-in-time view; values may change immediately after reading.
Returns all items currently in the buffer as an array, without
removing them. Same caveats as each about concurrency.