A lightweight, header-only circular buffer that mirrors the API in RingBuffer.h.
- Template-based buffer supporting any
Twith a power-of-two capacityN. - ESP32-friendly: per-instance spinlocks guard critical sections when
ARDUINO_ARCH_ESP32is defined. - Overload-aware helpers for single items or contiguous blocks when calling
push,pop,peek, andconsume. - Runtime helpers:
available(),capacity(), andclear()provide buffer insights and maintenance. - Optional overwriting behaviour during
pushto discard oldest data when the buffer is full.
The class exposes the following methods:
push(const T& data, bool overwrite = false)push(const T* data, size_t data_len, bool overwrite = false)pop(T& output)pop(T* output, size_t len)peek(T& output) constpeek(T* output, size_t len) constconsume()consume(size_t len)available() constcapacity() constclear()
The buffer automatically resets head and tail indexes when emptied and maintains a bounded element count to prevent overflow.
Clone or download uutzinger/RingBuffer into your Arduino libraries folder.
None
Urs Utzinger, 2025 ChatGPT, OpenAI
See LICENSE.