Page 1 of 1

max contiguous memory allocation on ESP32 ?

Posted: Wed Jun 28, 2023 8:25 pm
by marccof
Hi,

I would like to allocate a large buffer of 150KB on the ESP32 (without using the SPIRAM). I had a look at the documentation and it seems like it should be possible to allocate up to 160Kb in DRAM however I do cannot find out how to do that (from Arduino IDE).

I tried static allocation via:

Code: Select all

static uint8_t buffer[1024*150]
but this fails with the linker complaining that its overflowing the "dram0_0_seg" region.

I also tried to malloc the memory on the heap with

Code: Select all

uint8_t * buffer = malloc(1024*150);
but this also fails (with malloc returning a null pointer).

I am experimenting on an otherwise empty .ino script to minimize external memory fragmentation (no Wifi library or anything else that may use memory in the background). I am using Arduino 2.1 IDE and I tried building the script for several different ESP32 profiles: "ESP32 Dev Module" , "ESP32 Wrover module" ... but it always fails.

Doesn't the ESP32 memory map contain a contiguous 150Kb of RAM available ? Note that when compiling for a ESP32-S3 module instead, I have no problem fitting the 150K buffer in memory.

Thanks in advance for any help/pointers on how to increase the maximum amount of contiguous memory that can be allocated on ESP32 (without using the SPIRAM).

Re: max contiguous memory allocation on ESP32 ?

Posted: Thu Jun 29, 2023 1:40 am
by ESP_Sprite
No, it generally doesn't, sorry. The memory map on the ESP32 is a bit weird wrt fragmentation; as you noticed we improved on that with the S3.

Re: max contiguous memory allocation on ESP32 ?

Posted: Thu Jun 29, 2023 10:04 pm
by marccof
Ok. Thanks for the confirmation.
Then I will have to make do with what is available... :)

Re: max contiguous memory allocation on ESP32 ?

Posted: Fri Jun 30, 2023 7:17 pm
by lbernstone
You can find out how much is available for allocation with ESP.getMaxAllocHeap or heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL)