How to observe if program runs out of heap

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

whats the best way to see how much heap i should set for my program? How to detect if there is not enough heap?

   

Thanks,

   

Patrick

0 Likes
1 Solution
Anonymous
Not applicable

Always recommended to keep the HeapSize as 0x400 and heap size as 0x800 to be on safer side.

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Always recommended to keep the HeapSize as 0x400 and heap size as 0x800 to be on safer side.

0 Likes
Anonymous
Not applicable

Can you call the USBDevice->Reset() and then IsOpen?

0 Likes
Anonymous
Not applicable

Hi,

   

right now i have the Heap size at 0x800 and the stack size also at 0x800. When i had the heap at 0x400 the BLE stack hang up. I also have quite som printf()'s in my program for debugging, i think thats whats eating up the heap.

   

Anyways, what i was looking for was a way to see something like "oh, ok so i use now 79 % of my heap, i could turn it down a bit", so i want to have something like a level indicator for the heap. Is that what you want to do with the IsOpen?

   

Can you clarify the process you suggested, i dont really know what to do exactly.

   

Thanks,

   

Patrick

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

To be honest, there is no need to "turn down the heap".

   

You have got 3 ram memory areas: Program static data, stack and heap. Any ram that is not in the range of one of the areas is non-existing for your C-program and as such not (easily) accessible. Static data area and stack are fixed, so best practice would be to use all the rest for the heap. Unfortunately this is not done automatically as in other languages like PASCAL. So (as long as this is not changed) you will have to calculate your heap amount yourself and check the resulting pointer from malloc() to be non-NULL.

   

EDIT:

   

Of course you may encapsulate malloc() and free() into your own routines and so keeping track of the amount of heap currently in use.

   

Bob

0 Likes