cancel
Showing results for 
Search instead for 
Did you mean: 

how to check remaining heap size

ckw089
Associate II

We are using stm32h750xb for our project running uC/OS-II RTOS.

Question: is there a way to check the remaining heap size for the system at any point of time after the product is up and running.

5 REPLIES 5

It is usually a linked list, walk it and understand the arena.

The exact implementation will be compiler/library specific, but is not complicated. Usually you'll find the linking structures below the address returned by malloc(), with initial heap pointers exposed as symbols.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ckw089
Associate II

​We are using the IAR Embedded Workbench for ARM. And the ‘malloc()’ function is actually calling ‘__iar_dlmalloc()’. I believe IAR is using the Doug Lea's Memory Allocator.

 I found the below technical note on IAR web site. Anyone has experience of using ‘__iar_dlmallinfo()’ and ‘__iar_dlmalloc_stats()’ mentioned in the technical note ?

https://www.iar.com/support/tech-notes/general/iar-dlib-library-heap-usage-statistics/

Uwe Bonnes
Principal III

Best is to avoid dynamic allocation during runtime and only use it with setup...

Indeed, it can work for initial allocations based on user configuration or mode of operation settings, rather than compile time statics.

I think however it is important to understand basic CS concepts like heaps and linked lists, and have an awareness of how they work, and the issues with fragmentation and resource leaks.

In the last uCOSII design I worked on we needed some dynamic allocation of resources, and used a memory pool with various sized objects to manage that. And did a lot of testing, analysis and reporting to identify resource leaks, as the devices were expected to run continuously for years.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

OK, thanks for the suggestion.