Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
I am chasing down a heap issue and I am confused about the heap structure.
In the makefile, I am setting PLATFORM_HEAP_SIZE=256*1024. We have some large JSON structures and when we convert them to strings they can get over 100k characters.
When I print heap information using the example from command_console_mallinfo.c, I get the following
arena: 31000; /* total space allocated from system */
ordblks: 4; /* number of non-inuse chunks */
smblks: 0; /* unused -- always zero */
hblks: 0; /* number of mmapped regions */
hblkhd: 0; /* total space in mmapped regions */
usmblks: 0; /* unused -- always zero */
fsmblks: 0; /* unused -- always zero */
uordblks: 26512; /* total allocated space */
fordblks: 4488; /* total non-inuse space */
keepcost: 2048; /* top-most, releasable (via malloc_trim) space */
Total heap size: 31000 bytes
Memory in use: 26512 bytes
sbrk heap start: 0x004F76E8; size: 1739024
sbrk current free: 1708024
Total free memory: 1712512
I do not see a 256kB stack anywhere; it looks like the "total area" is 31000 bytes. In fact I am not sure what the difference between arena, heap and sbrk heap are. I could not find this in the SDK documentation.
I some later point, the heap info looks like this and all malloc() calls are failing:
sbrk heap size: 1739024
sbrk current free: 4088
malloc arena: 1734936
malloc allocated: 395672
malloc free: 1339264
Total free memory: 1343352
It looks like the memory has migrated from one heap to another, and malloc() is failing because there is very little memory left in the heap.
Do you know what could cause this heap migration? We are using the cJSON library very heavily during these logs.
How do I ensure there is ample heap available for the large JSON strings?