Analyze Heap size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Analyze Heap size

Jump to solution
3,963 Views
hiroshihiraga
NXP Employee
NXP Employee

Hi, 

Is it possible to analyze a heap size? 

I know that there is a feature of FreeRTOS heap size monitoring. 

Standard C library malloc or even sprintf uses heap memory that is not managed region of memory by RTOS.

I think such standard C library is not recommended to use when RTOS is used due to non thread safe. But, some customers still want to use such C standard library and analyze the heap size.

Hiroshi,

Labels (1)
0 Kudos
1 Solution
3,859 Views
converse
Senior Contributor V

Mixing heaps (C library and FreeRTOS) is not a good idea and could lead to some very hardtop-debug issues. However, if you insist, then see

Heap allocation/checking in Redlib 

and the final reply here

https://community.nxp.com/thread/521689 

View solution in original post

0 Kudos
5 Replies
3,859 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Hiroshi,

MCUxpresso IDE has tools for FreeRTOS HEAP usage monitor. This is the easiest way.

FreeRTOS itself hasn't such a library. There is some discuss on internet about how to monitor. People have to write monitor code by themselves.

Regards,

Jing

0 Kudos
3,859 Views
hiroshihiraga
NXP Employee
NXP Employee

HI, jingpan

Thanks, ok. I will look up the internet.

And, don't you have any information about monitoring the heap size that is not managed by RTOS?

Hiroshi,

0 Kudos
3,860 Views
converse
Senior Contributor V

Mixing heaps (C library and FreeRTOS) is not a good idea and could lead to some very hardtop-debug issues. However, if you insist, then see

Heap allocation/checking in Redlib 

and the final reply here

https://community.nxp.com/thread/521689 

0 Kudos
2,876 Views
danielholala
Senior Contributor II

How do you avoid mixing heaps in case you want to use FreeRTOS and C library functions when some of them use malloc() and free()?

I see at least to possible approaches:

  • Redirect malloc() and free() to their FreeRTOS equivalents defined in one of the heap memory schemes

OR

  • Define the stubs needed for malloc/free to work (e.g., sbrk(), ...) and implement FreeRTOS pvPortMalloc() and vPortFree() by using malloc()/free()

The latter is Dave Nadler's approach.

Maybe you suggest a different third approach?

Thanks!
Dan

 

0 Kudos
2,855 Views
danielholala
Senior Contributor II

Ups, have to reply to myself.

I read that Dave Nadler already tried the first approach and stopped after he figured that FreeRTOS heap implementations would not support realloc()directly.  One would have to implement this function.

So I guess the easiest way is to redirect pvPortMalloc() and vPortFree() using D. Nadler's code. However, with this approach, one forfeits the use of Heap View in MCUXpresso IDE.

0 Kudos