Bedtime. /Memory Management

Memory Management

Dynamic memory allocation from FreeRTOS heap

void* os_malloc(size_t size)

Allocate memory from heap

size_tsizeNumber of bytes to allocate

Returns — Pointer to allocated memory, or NULL if out of memory

void* buffer = os_malloc(1024);
if (buffer) {
    // Use buffer
    os_free(buffer);
}

Note — Memory is limited - always check return values

Note — Large blocks may be served from external PSRAM, which is write-back cached and fine to use at audio rate (delay lines, sample buffers). Internal RAM still has the lowest worst-case latency, so keep your very hottest per-sample state small — smaller blocks are more likely to land internal.

void os_free(void* ptr)

Free memory allocated with os_malloc

void*ptrPointer returned by os_malloc (NULL is safely ignored)