RE: [gtk-list] Re: Benchmarking glib (atleast GList) (was: how ca n I trust glib when it has so many memleaks?)



Tim, 

Thank you very much.  This is the exactly what I was looking
for. This also allows others to actually free the nodes when
they are finished.

Thanks

Steve.

> -----Original Message-----
> From:	Tim Janik [SMTP:timj@gtk.org]
> Sent:	Monday, March 22, 1999 4:58 PM
> To:	'gtk-list@redhat.com'
> Subject:	[gtk-list] Re: Benchmarking glib (atleast GList) (was: how
> ca n I trust glib when it has so many memleaks?)
> 
> 
> if you have a certain portion of code that uses *lots* of GLists or
> GNodes, and you know you'd better want to release all of them after
> a short while, you'd want to use a GAllocator. pushing an allocator
> into g_list will make all subsequent glist operations private to that
> allocator's memory pool (and thus you have to take care to pop the
> allocator again, before making any external calls):
> 
> GAllocator *allocator;
> GList *list = NULL;
> guint i;
> 
> /* set a new allocation pool for GList nodes */
> allocator = g_allocator_new ("list heap", 1024);
> g_list_push_allocator (allocator);
> 
> /* do some list operations */
> for (i = 0; i < 4096; i++)
>   list = g_list_prepend (list, NULL);
> list = g_list_reverse (list);
> 
> /* beware to pop allocator befor calling external functions */
> g_list_pop_allocator ();
> gtk_label_set_text (GTK_LABEL (some_label), "some text");
> 
> /* and set our private glist pool again */
> g_list_push_allocator (allocator);
> 
> /* do some list operations */
> g_list_free (list);
> list = NULL;
> for (i = 0; i < 4096; i++)
>   list = g_list_prepend (list, NULL);
>   
> /* and back out (while freeing all of the list nodes in our pool) */
> g_list_pop_allocator ();
> g_allocator_free (allocator);
> 
> 
> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]