This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
anybody use mallinfo?
- From: Richard dot von dot Lehe at gd-ais dot com
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Tue, 17 Aug 2004 17:48:32 -0500
- Subject: [ECOS] anybody use mallinfo?
Hi All,
I thought I would experiment to see if mallinfo is usable and maybe use it to get an idea of how much heap we're using. I created a simple test program that spits out the mallinfo struct before a 'new', after a 'new', and after a 'delete'. I thought that the pre-new and post-delete values would be the same, but it didn't turn out that way.
The uordblocks increases by 1008 after 'new'ing 1000 chars. I would have thought it should be 1000, but whatever. Then, it doesn't decrease after the 'delete []' call. Does all this just mean that the implementation of mallinfo is not complete and I should stay away from it or am I misunderstanding something?
This is on the A&M Rattler boards if that makes any difference.
Thanks!
Rich
Here's the program and output:
<---- CODE ----->
int main(int argc, char* argv[])
{
struct mallinfo minfo;
char* pChar;
minfo = mallinfo();
diag_printf("arena:%d ordblks:%d smblks:%d hblks:%d hblkhd:%d\n", minfo.arena,
minfo.ordblks, minfo.smblks, minfo.hblks, minfo.hblkhd);
diag_printf("usmblks:%d fsmblks:%d uordblks:%d fordblks:%d keepcost: %d\n",
minfo.usmblks, minfo.fsmblks, minfo.uordblks, minfo.fordblks,
minfo.keepcost);
pChar = new char[1000];
strcpy(pChar, "The quick brown fox jumps over the lazy dog.");
minfo = mallinfo();
diag_printf("arena:%d ordblks:%d smblks:%d hblks:%d hblkhd:%d\n", minfo.arena,
minfo.ordblks, minfo.smblks, minfo.hblks, minfo.hblkhd);
diag_printf("usmblks:%d fsmblks:%d uordblks:%d fordblks:%d keepcost: %d\n",
minfo.usmblks, minfo.fsmblks, minfo.uordblks, minfo.fordblks,
minfo.keepcost);
delete [] pChar;
minfo = mallinfo();
diag_printf("arena:%d ordblks:%d smblks:%d hblks:%d hblkhd:%d\n", minfo.arena,
minfo.ordblks, minfo.smblks, minfo.hblks, minfo.hblkhd);
diag_printf("usmblks:%d fsmblks:%d uordblks:%d fordblks:%d keepcost: %d\n",
minfo.usmblks, minfo.fsmblks, minfo.uordblks, minfo.fordblks,
minfo.keepcost);
return 0;
}
<----- end code ----->
Output:
arena:14955096 ordblks:1 smblks:0 hblks:0 hblkhd:0
usmblks:0 fsmblks:0 uordblks:528 fordblks:14954548 keepcost: 0
arena:14955096 ordblks:1 smblks:0 hblks:0 hblkhd:0
usmblks:0 fsmblks:0 uordblks:1536 fordblks:14953540 keepcost: 0
arena:14955096 ordblks:1 smblks:0 hblks:0 hblkhd:0
usmblks:0 fsmblks:0 uordblks:1536 fordblks:14953540 keepcost: 0
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss