You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RingBuffer exposes no length or capacity, so callers can't tell whether the next PushBack evicts, and can't write Resample(buffer.Length * 2) #148
RingBuffer<T> stores its logical length but keeps it private:
Containers/RingBuffer.cs:58: private int Capacity { get; set; }
Containers/RingBuffer.cs:63: private int Length { get; set; }
Containers/RingBuffer.cs:68: public int Count { get; private set; }, the only size member that is public
Code that receives a RingBuffer<T> can see only Count. It cannot read the length the buffer was built with (new RingBuffer<T>(length), Resize(length), Resample(length)), so it cannot tell a part-filled buffer from a full one.
The sibling containers do expose a capacity: SpscRingBuffer<T>.Capacity (SpscRingBuffer.cs:85), DelayLine.Capacity (DelayLine.cs:72) and ContiguousCollection<T>.Capacity (ContiguousCollection.cs:67).
Concrete failure scenarios
Sliding window "is it warmed up yet?" Here is the common moving-average pattern:
There is nothing to compare Count against. The caller has to carry the length alongside the buffer and keep that copy in sync through every Resize/Resample.
Will this push evict?PushBack (RingBuffer.cs:172) silently drops the oldest element once Count == Length. A caller that wants to process or persist the element before it is lost cannot detect that state.
Relative resizing.buffer.Resample(buffer.Length * 2) or buffer.Resize(buffer.Length / 2) (RingBuffer.cs:252, :274) cannot be written. A part-filled buffer makes this worse: Count is not the length, so Resample(Count * 2) gives a different, wrong result.
Suggested fix / acceptance criteria
Add a public read-only int Length (or Capacity, to match the siblings; it is the logical length, not the power-of-two backing size) that returns the value passed to the constructor, Resize or Resample.
Optionally add bool IsFull => Count == Length.
Keep the power-of-two backing size private.
Tests: Length after each constructor overload, after Resize, after Resample, and after a failed Resize (which leaves the buffer unchanged); IsFull false while filling and true from the Length-th push on.
Priority: Low. Nothing is broken. Callers can work around it by carrying the length next to the buffer, and the sibling containers (SpscRingBuffer, DelayLine, ContiguousCollection) already expose Capacity. Adding the property is additive, so it can ship in any minor release.
Area / suggested assignment:RingBuffer<T> in Containers/RingBuffer.cs (the private Capacity/Length properties at lines 58–63). Owner: @matt-edmondson
Next step: Pick the name first. Capacity matches the sibling containers, but here it would mean the logical length, not the power-of-two backing size, so rename the private backing-size property to avoid a clash. Then add the read-only property and IsFull, with the tests listed in the issue.
Activity
matt-edmondson commentedon Nov 6, 2026
Triage
SpscRingBuffer,DelayLine,ContiguousCollection) already exposeCapacity. Adding the property is additive, so it can ship in any minor release.RingBuffer<T>inContainers/RingBuffer.cs(the privateCapacity/Lengthproperties at lines 58–63). Owner: @matt-edmondsonResample) and RingBuffer, SpscRingBuffer and DelayLine throw an undocumentedOverflowExceptionfor sizes above 2^30, and a failedRingBuffer.Resizecorrupts the buffer #89/Reject ring buffer sizes above 2^30 with ArgumentOutOfRangeException [patch] #114 (failedResizeleaves the buffer unchanged). The acceptance tests should rely on that behaviour. foreach over ContiguousCollection/ContiguousSet/ContiguousMap/RingBuffer is 3–4x slower than List/Dictionary and allocates every loop, because GetEnumerator is a boxed iterator method #134 (struct enumerators) also changesRingBuffer's public surface, so the two could go out in the same minor release.Capacitymatches the sibling containers, but here it would mean the logical length, not the power-of-two backing size, so rename the private backing-size property to avoid a clash. Then add the read-only property andIsFull, with the tests listed in the issue.Generated by Claude Code