eve.util.ringbuffer
A fixed-capacity ring buffer for byte data.
Part of EVE's Buffer Ownership Redesign (BUFFER-OWNERSHIP-REDESIGN.md §4.1). Provides Solution A: a pre-sized ring buffer that eliminates GC allocation on the send hot path when configured via preallocatedSendBuffer.
Designed for send-queue use in Layer 2 transports: pre-allocated once at connection setup, then zero-allocation in steady state. All hot-path methods are @nogc @safe nothrow.
Data is stored in a single contiguous ubyte[] slab. The write position (_head) and read position (_tail) wrap around modulo _capacity. _used tracks the number of live bytes so that the full/empty ambiguity is resolved without wasting a slot.
Layout when partially filled (no wrap): [....TTTTTTTTTHHHH........] ^tail ^head
Layout when wrapped: HHHH........TTTTTTTTTTTT ^head ^tail
Design decision: separate _used counter instead of the traditional "waste one slot" approach. This allows capacity() bytes of usable storage rather than capacity - 1, which matters for send queues where the buffer is sized to match highWaterMark.
Copyright
Types 1
Fixed-capacity ring buffer for ubyte data.
Allocation occurs once in initialize(). All subsequent operations are @nogc. Call dispose() to release the backing storage.
The struct is non-copyable (@disable this(this)) to prevent accidental duplication of the backing slice. Pass by reference or store as a field in a class.
Buffer Ownership (TERMINOLOGY.md): The backing storage is EVE-Owned after initialize(). append() uses Copy semantics — the caller may reuse or free the source buffer immediately. front() returns a Borrowed slice valid only until the next append() or consume() call.
ubyte[] _storagesize_t _capacitysize_t _headsize_t _tailsize_t _usedconst(ubyte)[] front() const @trusted nothrow @nogcGet a contiguous view of the front (readable) portion of the buffer.