max contiguous memory allocation on ESP32 ?

marccof
Posts: 2
Joined: Wed Jun 28, 2023 7:54 pm

max contiguous memory allocation on ESP32 ?

Postby marccof » Wed Jun 28, 2023 8:25 pm

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).

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: max contiguous memory allocation on ESP32 ?

Postby ESP_Sprite » Thu Jun 29, 2023 1:40 am

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.

marccof
Posts: 2
Joined: Wed Jun 28, 2023 7:54 pm

Re: max contiguous memory allocation on ESP32 ?

Postby marccof » Thu Jun 29, 2023 10:04 pm

Ok. Thanks for the confirmation.
Then I will have to make do with what is available... :)

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: max contiguous memory allocation on ESP32 ?

Postby lbernstone » Fri Jun 30, 2023 7:17 pm

You can find out how much is available for allocation with ESP.getMaxAllocHeap or heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL)

Who is online

Users browsing this forum: No registered users and 59 guests