Gin
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ScratchBuffer Class Reference

Temporary audio buffer allocated from a shared pool to avoid allocations. More...

#include <gin_scratchbuffer.h>

Inherits juce::AudioSampleBuffer.

Public Member Functions

 ScratchBuffer (int numChannels, int numSamples)
 
 ScratchBuffer (juce::AudioSampleBuffer &buffer)
 
 ScratchBuffer (const ScratchBuffer &)
 
 ~ScratchBuffer ()
 

Detailed Description

Temporary audio buffer allocated from a shared pool to avoid allocations.

ScratchBuffer provides a convenient way to get temporary audio buffers without allocating memory on the heap. Buffers are retrieved from a thread-safe pool and automatically returned when the ScratchBuffer goes out of scope.

This is useful in real-time audio code where you need temporary buffers but want to avoid allocation overhead and fragmentation. The pool grows as needed but buffers are reused, minimizing allocations after initialization.

Key Features:

Note: While buffer retrieval from the pool uses locking, this is generally acceptable as the lock contention is minimal and allocation is avoided.

Usage:

{
// Get a temporary buffer - no allocation if pool has one
ScratchBuffer temp(buffer.getNumChannels(), buffer.getNumSamples());
// Use it like a regular AudioBuffer
temp.copyFrom(0, 0, buffer, 0, 0, buffer.getNumSamples());
buffer.copyFrom(0, 0, temp, 0, 0, temp.getNumSamples());
// Buffer automatically returned to pool when temp goes out of scope
}
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
Temporary audio buffer allocated from a shared pool to avoid allocations.
Definition gin_scratchbuffer.h:58
See also
juce::AudioSampleBuffer

Constructor & Destructor Documentation

◆ ScratchBuffer() [1/3]

ScratchBuffer::ScratchBuffer ( int  numChannels,
int  numSamples 
)

◆ ScratchBuffer() [2/3]

ScratchBuffer::ScratchBuffer ( juce::AudioSampleBuffer &  buffer)

◆ ScratchBuffer() [3/3]

ScratchBuffer::ScratchBuffer ( const ScratchBuffer )

◆ ~ScratchBuffer()

ScratchBuffer::~ScratchBuffer ( )

The documentation for this class was generated from the following file: