Operating System - HP-UX
1829123 Members
2082 Online
109986 Solutions
New Discussion

How to find available heap memory

 
Sup
Advisor

How to find available heap memory

Hi,

I have progrma which is allocating memory
from heap using malloc() and this memory
is not freed. I want to find out how much
heap is left out during this program executing?
Is there any command which helps me?

Thanx
2 REPLIES 2
Sajid_1
Honored Contributor

Re: How to find available heap memory

Did you try GlancePlus? If installed check it:
# glance
# gpm
learn unix ..
A. Clay Stephenson
Acclaimed Contributor

Re: How to find available heap memory

If you are calling free() and are wondering why the process size does not shrink, this is normal behavior. Free() does not return memory to the system but rather simply pushes that memory back on the process'es free list for reuse by subsequent malloc()'s by the same process. If you want to return memory to the system then you must take control of memory allocation using sbrk() with a negative value BUT you cannot use malloc(), realloc(), calloc() or free. You must only use sbrk() and you can't use any library routines which call malloc() to allocate memory.
If it ain't broke, I can fix that.