freepmem in qnx_osinfo isn't updating correctly

I’m adding entries into a dynamic linked link, everytime before i add, i
use ‘qnx_osinfo()’ to get the total free memory available, for some reason,
freepmem isn’t updated to the correct value, freepmem could show me the same
value for awhile while i’m adding entries to the linked list, then all of
sudden, it decreased by large amount… sin freemem in the shell is showing
the same problem…

Ran Zhang wrote:

I’m adding entries into a dynamic linked link, everytime before i add, i
use ‘qnx_osinfo()’ to get the total free memory available, for some reason,
freepmem isn’t updated to the correct value, freepmem could show me the same
value for awhile while i’m adding entries to the linked list, then all of
sudden, it decreased by large amount… sin freemem in the shell is showing
the same problem…

This is standard heap management under QNX4 malloc library. It will
allocated memory from the OS into the local heap in minimum-sized chunks
(_amblksize I think is about 16k?) to carve up locally to malloc().
When you free() memory it returns to the process heap, and is not
returned to the OS until the process terminates. This is all to reduce
the amount of work the memory manager must do.

so is there a way to check exactly how much memory is left in the system at
a particular time in the software?
“John Garvey” <jgarvey@qnx.com> wrote in message
news:dst0e0$m5f$1@inn.qnx.com

Ran Zhang wrote:
I’m adding entries into a dynamic linked link, everytime before i add,
i
use ‘qnx_osinfo()’ to get the total free memory available, for some
reason,
freepmem isn’t updated to the correct value, freepmem could show me the
same
value for awhile while i’m adding entries to the linked list, then all
of
sudden, it decreased by large amount… sin freemem in the shell is
showing
the same problem…

This is standard heap management under QNX4 malloc library. It will
allocated memory from the OS into the local heap in minimum-sized chunks
(_amblksize I think is about 16k?) to carve up locally to malloc().
When you free() memory it returns to the process heap, and is not
returned to the OS until the process terminates. This is all to reduce
the amount of work the memory manager must do.

Ran Zhang wrote:

so is there a way to check exactly how much memory is left in the
system at a particular time in the software?

I think you’re asking if there is “a way to tell how much memory in
your local heap has not been allocated” (ie has been allocated from
OS memory into heap, but not used from heap to satisfy a malloc)?

Try (this is either QNX4- or Watcom-specific):

#include <malloc.h>
printf(“unused heap space is %d bytes\n”, _memavl());

Of somewhat dubious use though, since it may be fragmented in the
heap and your process is unable to allocate an object of that size
without having to go to the OS for more memory pages, plus malloc
will have its own overheads to link free/used blocks within the heap.