memory fragments

Hi!

Under QNX, is there any good way to analyse the memoy fragments after
hundreds of thousands of times malloc()/free() and new/delete pairs. and
moreover to get the system maxium size of the contiguous free memory block?

Thanks,


Yang WANG
BCI sa

“Yang WANG” <wy@bcisa.com> wrote in message
news:8pr33p$ihk$1@front2.grolier.fr

Hi!

Under QNX, is there any good way to analyse the memoy fragments after
hundreds of thousands of times malloc()/free() and new/delete pairs. and
moreover to get the system maxium size of the contiguous free memory
block?

Thanks,


Yang WANG
BCI sa

Here’s some code to dump the entries in the heap within a process. I’m not
sure what you mean by “the system maxium size of the contiguous free memory
block”. If a malloc in you process can’t satisfy the request with a free
block within the heap, it will ask the OS for more memory to add to the
heap. Are you interested in what’s free within the process’ heap, or in the
entire system?

Marty Doane


void heap_dump(void)
{
struct _heapinfo h_info;
int heap_status;

h_info._pentry = NULL;
for(;:wink:
{
heap_status = _heapwalk( &h_info );
if( heap_status != _HEAPOK ) break;
printf( " %s block at %Fp of size %4.4X\n",
(h_info._useflag == _USEDENTRY ? “USED” : “FREE”),
h_info._pentry, h_info._size );
}

switch( heap_status )
{
case _HEAPEND:
printf( “OK - end of heap\n” );
break;
case _HEAPEMPTY:
printf( “OK - heap is empty\n” );
break;
case _HEAPBADBEGIN:
printf( “ERROR - heap is damaged\n” );
break;
case _HEAPBADPTR:
printf( “ERROR - bad pointer to heap\n” );
break;
case _HEAPBADNODE:
printf( “ERROR - bad node in heap\n” );
}
}

Hi, Marty Doane!

Thks for your infos!

In facts, in our embeded applications, we have several processes with
certain life cycle respectively, which are managed and supervised by a
process watchdog.
And in watchdog, we use qnx_osinfo() to supervise the system free memory.
We suspect that certain process of our applications leaks memory so we
expect that we can analyse the memory fragements of one process and have
some way to know the maximum contiguous free memory of the entire system to
be
ensure that it can be really allocated even when a process demande a huge
memory.

Maybe what I want to do is not good. Anyway, I hope we can have some way to
know memory leaks moreover to avoid it and to use the limited memory
efficient.

regards,


\


Yang WANG
BCI sa

“Marty Doane” <doanemr@rapistan.com> wrote in message
news:8pt2ab$4et$1@inn.qnx.com

“Yang WANG” <> wy@bcisa.com> > wrote in message
news:8pr33p$ihk$> 1@front2.grolier.fr> …
Hi!

Under QNX, is there any good way to analyse the memoy fragments after
hundreds of thousands of times malloc()/free() and new/delete pairs. and
moreover to get the system maxium size of the contiguous free memory
block?

Thanks,


Yang WANG
BCI sa

Here’s some code to dump the entries in the heap within a process. I’m not
sure what you mean by “the system maxium size of the contiguous free
memory
block”. If a malloc in you process can’t satisfy the request with a free
block within the heap, it will ask the OS for more memory to add to the
heap. Are you interested in what’s free within the process’ heap, or in
the
entire system?

Futher more because QNX uses virtual memory, what may look like a

contiguous memory block, may physicaly not be…

In THEORY if you have 4 Megs of free ram, your application should
be able to get it. If that 4Meg is fragmented it shouldn’t matter because
each block will be made to look like they are contiguous. There are
limit to this, i’m not familiar with them however.

Marty Doane


void heap_dump(void)
{
struct _heapinfo h_info;
int heap_status;

h_info._pentry = NULL;
for(;:wink:
{
heap_status = _heapwalk( &h_info );
if( heap_status != _HEAPOK ) break;
printf( " %s block at %Fp of size %4.4X\n",
(h_info._useflag == _USEDENTRY ? “USED” : “FREE”),
h_info._pentry, h_info._size );
}

switch( heap_status )
{
case _HEAPEND:
printf( “OK - end of heap\n” );
break;
case _HEAPEMPTY:
printf( “OK - heap is empty\n” );
break;
case _HEAPBADBEGIN:
printf( “ERROR - heap is damaged\n” );
break;
case _HEAPBADPTR:
printf( “ERROR - bad pointer to heap\n” );
break;
case _HEAPBADNODE:
printf( “ERROR - bad node in heap\n” );
}
}

\