Interface RingBuffer
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
RingBufferImpl
A primitive int-based ring buffer (circular queue) backed by off-heap memory.
Designed for zero-allocation passing of indices (pointers) between threads. Implementations should support Single-Producer/Single-Consumer (SPSC) or Multi-Producer/Multi-Consumer (MPMC) semantics as needed.
-
Method Summary
Modifier and TypeMethodDescriptionintcapacity()The total capacity of the ring.voidclose()Releases the underlying off-heap memory.booleanisEmpty()booleanisFull()booleanoffer(int item) Offers an item to the ring.intpoll()Polls an item from the ring.intsize()The current number of items in the ring.
-
Method Details
-
offer
boolean offer(int item) Offers an item to the ring.- Parameters:
item- The item (index) to enqueue.- Returns:
- true if successful, false if full.
-
poll
int poll()Polls an item from the ring.- Returns:
- The item, or -1 (or a configured sentinel) if empty.
-
capacity
int capacity()The total capacity of the ring. -
size
int size()The current number of items in the ring. -
isEmpty
boolean isEmpty() -
isFull
boolean isFull() -
close
void close()Releases the underlying off-heap memory.- Specified by:
closein interfaceAutoCloseable
-