Skip to main content

Module buffer_storage

Module buffer_storage 

Source
Expand description

Pre-allocated buffer storage for real-time safe audio processing.

This module provides ProcessBufferStorage, which pre-allocates capacity for channel pointers during plugin setup. The storage is then reused for each render call without allocations.

§Pattern

This storage follows a consistent pattern across all plugin formats:

  1. Allocate storage once during setup (non-real-time)
  2. Clear storage at start of each render (O(1), no deallocation)
  3. Push pointers from host buffers (never exceeds capacity)
  4. Build slices from pointers

§Memory Optimization Strategy

The allocation strategy is config-based, not worst-case:

  • Channel counts: Allocates exact number of channels from bus config, not MAX_CHANNELS
  • Bus counts: Allocates only for buses that exist, not MAX_BUSES
  • Lazy aux allocation: No heap allocation for aux buses if plugin doesn’t use them
  • Asymmetric support: Mono input can have stereo output (allocates 1 + 2, not 2 + 2)

Examples:

  • Mono plugin (1in/1out): Allocates 2 pointers (16 bytes on 64-bit)
  • Stereo plugin (2in/2out): Allocates 4 pointers (32 bytes on 64-bit)
  • Stereo with sidechain (2+2in/2out): Allocates 6 pointers (48 bytes on 64-bit)
  • Worst-case (32ch x 16 buses): Would be MAX_CHANNELS * MAX_BUSES = 512 pointers (4KB)

This means simple plugins use 32x less memory than worst-case allocation.

§Real-Time Safety

  • clear() is O(1) - only sets Vec lengths to 0
  • push() never allocates - capacity is pre-reserved
  • No heap operations during audio processing
  • All allocations happen in allocate_from_config() (non-real-time)

Structs§

ProcessBufferStorage
Pre-allocated storage for audio processing channel pointers.