The ESP32 microcontroller has only a few hundred kilobytes of internal RAM. Fortunately the ESP32 AudioKit or ESP32 Wrover provide 8MB PSRAM where 4MB can be directly addressed.
More information how to use PSRAM in Arduino can be found here. The only thing to highlight is that PSRAM can not be allocated in global variables! This is quite unfortunate because I preferably like to do this, so that the compiler can inform about the total memory usage.
Finally there is a more generic way that can be used e.g. if you want to use PSRAM with any library that is not under your control. You can call the following “magical” function:
#include "esp_heap_caps.h" const int limit = 10000; heap_caps_malloc_extmem_enable(limit);
Then, when external memory is available and activated, the allocation strategy is to initially try
to satisfy smaller allocation requests with internal memory and larger requests
with external memory. This sets the limit between the two.