Hello! How can I measure the heap size (total and free space) at runtime?
Right now I'm working with some legacy code that makes a call to mallinfo()
That call returns a mallinfo struct that has a field named "arena"
According to this link:
https://man7.org/linux/man-pages/man3/mallinfo.3.html
The arena field should have the size of the heap. In my board, it is showing a size of 12672 bytes
I'm also using the field "uordblks" of the same struct to measure the currently used heap size and it shows a reasonable value of 9876 bytes, and if I remove some calls to malloc in the code, this value decreases. So it looks like the measurement is working.
But, I changed the default heap size in gcc_startup_nrf52840.S:59 to 8192 bytes (using SDK 17.0)
So, there's something wrong here since I can't have 12672 bytes of usable heap area and/or be using 9876 bytes of the heap if the max value defined in the startup file is 8192 bytes
Is the way I'm currently measuring it at runtime correct? Any suggestions on how to fix that? Maybe the actual default heap size is defined somewhere else?
I haven't set __HEAP_SIZE or the __STARTUP_CONFIG flags. so it should be defaulting to the hardcoded value in that startup file