Page 1 of 1

calloc fails even when free heap is large enough

Posted: Thu May 09, 2019 12:21 pm
by Jami17
On a ESP-CAM module with external RAM this allocation fails
p= calloc(80, 240);

This smaller request works ok:
p= calloc(60, 240);


But these functions report that there's sufficient heap space available:
xPortGetFreeHeapSize(): 3456208
heap_caps_get_largest_free_block(MALLOC_CAP_8BIT): 3426256


Why does calloc fail even when there's enough RAM available?

Is there a workaround available?

I am using: ESP-IDF v3.3-beta2-18-g0f927791b-dirty

Re: calloc fails even when free heap is large enough

Posted: Thu May 09, 2019 6:11 pm
by chegewara
Check options in menuconfig about how psram should be added to heap, because not always memory can be with calloc.
Also try to use:

Code: Select all

 heap_caps_malloc(..., MALLOC_CAP_SPIRAM)   
 

Re: calloc fails even when free heap is large enough

Posted: Sat May 11, 2019 9:02 pm
by Jami17
That did it !
Thank you very much.