Class: AudiobufferPool

Overview

Memory allocation is a blocking operation, therefore should be avoided in a real-time audio context. AudiobufferPool can allocate audio buffers from pre-allocated memory without any blocking. Every buffer has a retain count which can be incremented by calling retain and decremented by calling release. Whenever the retain count value reaches zero, the buffer is destroyed and its memory will be automatically reused for another buffer.

How to implement

AudiobufferPool::initialize();
...
void *buffer = AudiobufferPool::getBuffer(128); // Returns a 128 byte buffer with retain count set to 1
AudiobufferPool::retainBuffer(buffer); // Retains buffer (retain count = 2)
AudiobufferPool::releaseBuffer(buffer); // Releases buffer (retain count = 1)
AudiobufferPool::releaseBuffer(buffer); // Releases buffer

Methods

  • getBuffer

    METHOD
    Creates a buffer with retain count set to 1, similar to an NSObject in Objective-C. Use releaseBuffer() to release. This method never blocks, never locks, is very fast and safe to use in a realtime thread. Can be called concurrently on any thread.
    Parameters
    NameTypeDefaultDescription
    sizeBytesunsigned intThe requested buffer's size in bytes. Maximum: 8388608 (8 MB).
    Returns
    TypeDescription
    void *The buffer.
  • initialize

    METHOD
    Initializes the buffer pool.
    Parameters
    None
    Returns
    None
  • releaseBuffer

    METHOD
    Release a buffer, similar to an NSObject in Objective-C (decreases the retain count by 1, the memory will be freed after retain count reaches 0). This method never blocks, never locks, is very fast and safe to use in a realtime thread. Can be called concurrently on any thread.
    Parameters
    NameTypeDefaultDescription
    buffervoid *The buffer.
    Returns
    None
  • retainBuffer

    METHOD
    Retains a buffer, similar to Objective-C (increases the retain count by 1, similar to an NSObject in Objective-C). This method never blocks, never locks, is very fast and safe to use in a realtime thread. Can be called concurrently on any thread.
    Parameters
    NameTypeDefaultDescription
    buffervoid *The buffer.
    Returns
    None
Javascript

is not supported here.

v1.0.6