On esp32, attempt to always allocate in psram first.
| 38 | #ifdef FL_IS_ESP32 |
| 39 | // On esp32, attempt to always allocate in psram first. |
| 40 | void *DefaultAlloc(fl::size size) { |
| 41 | #ifdef FL_VECTOR_PSRAM_ALWAYS_SRAM |
| 42 | // FL_VECTOR_PSRAM_ALWAYS_SRAM: skip PSRAM, use default (SRAM) only. |
| 43 | void *out = heap_caps_malloc(size, MALLOC_CAP_DEFAULT); |
| 44 | #else |
| 45 | void *out = heap_caps_malloc(size, MALLOC_CAP_SPIRAM); |
| 46 | if (out == nullptr) { |
| 47 | // Fallback to default allocator. |
| 48 | out = heap_caps_malloc(size, MALLOC_CAP_DEFAULT); |
| 49 | } |
| 50 | #endif |
| 51 | return out; |
| 52 | } |
| 53 | void DefaultFree(void *ptr) { heap_caps_free(ptr); } |
| 54 | #else |
| 55 | void *DefaultAlloc(fl::size size) { return malloc(size); } |