ScratchBuffer
Source:
ScratchBuffer.h
ScratchBuffer¶
src/core/ScratchBuffer.h:55Inherits:
ScratchBufferBase
Typed façade — pure inline sugar over ScratchBufferBase.
Every method folds into its call site, so a new T adds ~0 flash. The ONE static_cast in the whole design lives in data(). Effects declare ScratchBuffer<T> name_{*this}; and use [resize()]/count()/operator[]/operator bool — no void*, no sizeof, no cast.
Public Methods¶
inline explicit ScratchBuffer(MoonModule & owner)
inline bool resize(std::size_t count)
: Size to hold count elements (0 frees). Returns true on success.
inline T * data()
inline constT * data() const
inline std::size_t count() const
inline std::size_t bytes() const
inline explicit operator bool() const
inline T & operator[](std::size_t i)
inline constT & operator[](std::size_t i) const
ScratchBufferBase¶
src/core/ScratchBuffer.h:21Type-erased base for ScratchBuffer<T>: owns the one platform::alloc, the raw void*, the owner tie (dynamic-bytes delta accounting + free-on-disable registration), and the sole heavy body (resizeBytes).
Compiled ONCE in ScratchBuffer.cpp — no per-T duplication, so a device with several element types pays for this logic once, not per type. Not used directly; ScratchBuffer<T> is the public face.
This is the "type-erased base + thin typed façade" split (the same trick std::vector implementations use to share code across element types), applied so a memory-holding effect writes heat_.resize(n) and nothing else — the primitive is the free-helper, the destructor, the setDynamicBytes call, and the null-guard, all at once.
Friends¶
friend class MoonModule