Implementing a heap watermark

Rob Meades Rob.Meades@u-blox.com
Sun Nov 8 17:14:05 GMT 2020


I run/test my library code on various embedded processors (STM32F4, NRF52/53, ESP32), all of which use newlib.

I need to implement a "minimum heap ever available" watermark kind of function so that, after my tests are run, I can be sure that I have left sufficient room for user code to obtain heap memory.

Such a facility does not seem to be available in newlib out of the box: does anyone have any recommendations on how to go about implementing such a function?

For instance, is the newlib malloc()ater guaranteed to only call sbrk() when it really needs more memory, as opposed to when it might have free blocks available but it is "cheaper" to call sbrk() then to allocate from those blocks?  If the former then simply monitoring sbrk() would do the job for me.  If the latter then I probably have to intercept the malloc()/free() calls to track what's going on.

Rob



More information about the Newlib mailing list