Re: [gtk-list] Re: how can I trust glib when it has so many mem leaks?
- From: Kevin Handy <kth srv net>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: how can I trust glib when it has so many mem leaks?
- Date: Thu, 18 Mar 1999 15:32:03 -0700
Lars Hallberg wrote:
>
> Strange (that glib was ever faster). To my anderstanding g_malloc is
> just a wraper for malloc an shuld be one functioncall overhed slover!
>
> It is only when using memory shunks that glib alloc room for more
> equaly sized objects in one malloc and then just hands them out. When
> individual objects is freed the shunk is keept but if You destroy
> the hole shunk the memory is actuly freed... Or??? Should I red the
> source before making more stuped questions ;-) ?
>
> What i try to say anyway is that it is relativly pointless profiling
> g_alloc / malloc. List nods (witch are shrunks in glib) versus
> malloc do make more sens to profile....
Probibly what is happening, is that since both sets of tests are in
the same program, it doesn't dump out the memory that was allocated
for the malloc/free tests, which gives the g_alloc/g_free tests an
advantage because it can make use of the (allready) cached memory in
malloc/free.
I've split the program up into two, an the malloc/free is now faster
for a single iteration. I also added code to allow changing the size
multiplier to see if that made much difference between the two (it
didn't). Also lost the malloc(0)'s
you now call it as
./malloctest <loops> <sizemult> <test>
where
loops = # iterations of the test
sizemult = multiplier for the size of the malloc's
test = 1 for malloc/free
test = 2 got g_malloc/g_free
for example
./malloctest 100 200 1
./malloctest 100 200 2
to run the tests 100 times on malloc's sized between from 200 (200*1) to
3000 (200*15).
------------
#include <stdio.h>
#include <gtk/gtk.h>
GTimer *timer = NULL;
int
main( int argc, char **argv )
{
int max = atoi( argv[1] );
int MULTIPLIER = atoi( argv[2] );
int test = atoi( argv[3] );
char* testname;
int i, j;
void* xlist[100];
timer = g_timer_new();
g_timer_reset( timer );
switch(test)
{
case 1:
testname = "malloc/free";
for( j = 0; j < max; j++ ) {
for( i = 0; i < 100; i++ ) {
xlist[i] = (void*)malloc((i % 15 + 1) * MULTIPLIER);
}
for( i = 0; i < 100; i++ ) {
free(xlist[i]);
}
}
break;
case 2:
testname = "g_malloc/g_free" ;
g_timer_reset( timer );
for( j = 0; j < max; j++ ) {
for( i = 0; i < 100; i++ ) {
xlist[i] = g_malloc((i % 15 + 1) * MULTIPLIER);
}
for( i = 0; i < 100; i++ ) {
g_free(xlist[i]);
}
}
break;
default:
printf( "Undefined test\n");
exit(1);
}
printf( "%-20.20s ... %12d nodes*%-6d in %12.10g secs\n",
testname, max * 100, MULTIPLIER,
g_timer_elapsed( timer, NULL ) );
return( 0 );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]