Skip to content

Buffer

Source: Buffer.h

Buffer

class Buffer
src/light/layers/Buffer.h:29

Contiguous light-data buffer, shared between the layers that write it (effects) and the driver groups that read it.

When memory allows, layers and driver groups each own a buffer (so they run in parallel); when memory is tight, one buffer is shared.

Storage: a raw uint8_t* (not RGB*), so any channel layout fits — RGB, RGBW, or multi-channel DMX fixtures — addressed by channel count + offset. Allocated once via platform::alloc (PSRAM when available) outside the hot path and reused every frame; a std::span<uint8_t> view is the zero-cost safe accessor.

Locking: a semaphore costs ~150 bytes on ESP32, so prefer lock-free patterns — an atomic pointer swap for double-buffering, a single-slot SPSC handoff, or one shared semaphore across layers rather than one per layer.

Prior art: MoonLight's VirtualLayer.virtualChannels — a raw uint8_t* sized by channelsPerLight * nrOfLights, RGB/RGBW/DMX via LightsHeader offsets (https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Layers/VirtualLayer.h).

Public Methods

Buffer() = default : Defaulted constructor.

Buffer(constBuffer &) = delete : Deleted constructor.

inline Buffer(Buffer && other) noexcept

inline bool allocate(nrOfLightsType nrOfLights, uint8_t cpl)

inline void free()

inline void clear()

inline uint8_t * data()

inline constuint8_t * data() const

inline std::span< uint8_t > span()

inline std::span< constuint8_t > span() const

inline nrOfLightsType count() const

inline uint8_t channelsPerLight() const

inline size_t bytes() const