Skip to content

Buffer

Source: Buffer.h

Buffer

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

The contiguous light data every effect writes and every driver reads.

Allocated once outside the hot path and reused each frame. A layer and a driver group each own one when memory allows, and share one when it is tight. @moreinfo

Any channel layout fits

The storage is a raw byte array rather than a pixel type, addressed by channel count and offset. That is what lets RGB, RGBW and multi-channel DMX fixtures share one buffer. A std::span view is the zero-cost safe accessor over it.

Locking is avoided, not optimized

A semaphore costs around 150 bytes on an ESP32, so the patterns here stay lock-free. An atomic pointer swap for double buffering, or one shared semaphore across layers.

Public Methods

Buffer() = default : An empty buffer, holding nothing until it is allocated.

inline ~Buffer() : Release the allocation this buffer owns.

Buffer(const Buffer &) = delete : Never copied: the buffer owns its allocation and two owners would double-free it.

inline Buffer(Buffer && other) noexcept : Take over another buffer's allocation, leaving it empty.

inline bool allocate(nrOfLightsType nrOfLights, uint8_t cpl) : Size the buffer for nrOfLights at cpl channels each, returning false when memory refuses.

inline void free() : Release the allocation and report the buffer as empty.

inline void clear() : Set every channel to zero, leaving the allocation in place.

inline uint8_t * data() : The raw bytes, for a writer.

inline const uint8_t * data() const : The raw bytes, for a reader.

inline std::span< uint8_t > span() : A bounds-carrying view of the bytes, for a writer.

inline std::span< const uint8_t > span() const : A bounds-carrying view of the bytes, for a reader.

inline nrOfLightsType count() const : How many lights the buffer holds.

inline uint8_t channelsPerLight() const : How many bytes each light occupies.

inline size_t bytes() const : How many bytes the lights occupy.