The information about the heap displayed at boot time isn't all that counts. What's also important is the largest_free_block of memory available on the heap when malloc is invoked. There's a function called heap_caps_print_heap_info which can be invoked to print information about memory that can be allocated with malloc like this:
Code: Select all
heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
It displays information similar to this:
Code: Select all
Heap summary for capabilities 0x00001000:
At 0x3ffae6e0 len 6432 free 0 allocated 6296 min_free 0
largest_free_block 0 alloc_blocks 26 free_blocks 0 total_blocks 26
At 0x3ffb2ed0 len 184624 free 169724 allocated 14788 min_free 168776
largest_free_block 169724 alloc_blocks 19 free_blocks 1 total_blocks 20
At 0x3ffe0440 len 15072 free 15036 allocated 0 min_free 15036
largest_free_block 15036 alloc_blocks 0 free_blocks 1 total_blocks 1
At 0x3ffe4350 len 113840 free 113804 allocated 0 min_free 113804
largest_free_block 113804 alloc_blocks 0 free_blocks 1 total_blocks 1
Totals:
free 298564 allocated 21084 min_free 297616 largest_free_block 169724
On this system the largest free block is 169724 bytes and it would be possible to successfully invoke malloc to allocate this amount of memory.
If you call heap_caps_print_heap_info on your system directly before calling malloc it will display the amount of free memory available.
For more information see:
https://docs.espressif.com/projects/esp ... alloc.html
and:
https://docs.espressif.com/projects/esp ... debug.html