How to increase ram for dynamic allocation

Posts: 398
Joined: Tue Mar 20, 2018 11:36 am

How to increase ram for dynamic allocation

Postby Deouss » Mon Jan 07, 2019 4:15 pm

I need to allocate minimum 120Kb of RAM with malloc or calloc.
During start the heap information is listed:
heap_init: Initializing. RAM available for dynamic allocation:
I (327) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (333) heap_init: At 3FFB8EA0 len 00027160 (156 KiB): DRAM
I (339) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (345) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (352) heap_init: At 4008F0CC len 00010F34 (67 KiB): IRAM
However malloc() of 120kb fails...

Are there any settings in sdconfig or anywhere that could help here?
Thank you

User avatar
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: How to increase ram for dynamic allocation

Postby fly135 » Mon Jan 07, 2019 5:11 pm

If you aren't using Bluetooth you can release a lot of memory with this....


If you have external SPI ram then you can allocate from it with....

heap_caps_malloc(size, MALLOC_CAP_SPIRAM);

Posts: 47
Joined: Thu Dec 20, 2018 9:47 am

Re: How to increase ram for dynamic allocation

Postby fivdiAtESP32 » Mon Jan 07, 2019 7:08 pm

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

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
    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: ... alloc.html
and: ... debug.html

Who is online

Users browsing this forum: No registered users and 21 guests