Re: Disabling memory chunks and free list in glib



On Mon, 18 Dec 2000, Alexander Larsson wrote:

> Here is a preliminary patch that adds a configure option that disables all
> memory chunks and free lists in glib.
> 
> I don't know if this is the correct way to to this, as by disabling the
> memchunk code the application developer cannot use mem chunks either. On
> the other hand it is a lot cleaner that going through all GMemChunk users
> in glib and gtk+.

i think this is the right thign to do. if the application wants to be perfectly
suited for a system with sparse memory, it's probably not going to use memchunks
anyways, the main concern here is to get rid of wastefull behaviour in the
underlying libraries, which your patch takes care off.

> Comments?

jup, they went below.
this can go into cvs once you fixed g_nodes_free().
could you resend me your malloc-virtualization patch btw?
i'm not sure what the last version was.

> 
> / Alex
> 
> Index: configure.in
> ===================================================================
> RCS file: /cvs/gnome/glib/configure.in,v
> retrieving revision 1.162
> diff -u -p -r1.162 configure.in
> --- configure.in	2000/12/12 07:31:56	1.162
> +++ configure.in	2000/12/18 16:00:28
> @@ -105,6 +105,7 @@ AC_ARG_ENABLE(msg-prefix, [  --enable-ms
>  AC_ARG_ENABLE(mem_check, [  --enable-mem-check      turn on malloc/free sanity checking [default=no]],,enable_mem_check=no)
>  AC_ARG_ENABLE(mem_profile, [  --enable-mem-profile    turn on malloc profiling atexit [default=no]],,enable_mem_profile=no)
>  AC_ARG_ENABLE(gc_friendly, [  --enable-gc-friendly    turn on garbage collector friendliness [default=no]],,enable_gc_friendly=no)
> +AC_ARG_ENABLE(mem_pools, [  --disable-mem-pools     disable all glib internal memory pools [default=no]],,disable_mem_pools=no)

s/glib internal memory pools/glib memory pools/, since they are not
used by glib exclusively.

> +void
> +g_mem_chunk_destroy (GMemChunk *mem_chunk)
> +{

g_return_if_fail (mem_chunk != NULL); still here

> +  g_free (mem_chunk);
> +}
> +
> +gpointer
> +g_mem_chunk_alloc (GMemChunk *mem_chunk)
> +{
> +  GMinimalMemChunk *minimal = (GMinimalMemChunk *)mem_chunk;

here as well, and for the below also.

> +
> +  return g_malloc (minimal->alloc_size);
> +}

> +#ifndef DISABLE_MEM_POOLS
>  /* node allocation
>   */
>  struct _GAllocator /* from gmem.c */
> @@ -167,6 +168,30 @@ g_nodes_free (GNode *node)
>    current_allocator->free_nodes = node;
>    G_UNLOCK (current_allocator);
>  }
> +#else /* DISABLE_MEM_POOLS */
> +
> +GNode*
> +g_node_new (gpointer data)
> +{
> +  GNode *node;
> +
> +  node = g_new (GNode, 1);
> +
> +  node->data = data;
> +  node->next = NULL;
> +  node->prev = NULL;
> +  node->parent = NULL;
> +  node->children = NULL;
> +
> +  return node;
> +}
> +
> +static void
> +g_nodes_free (GNode *node)
> +{
> +  g_free (node);
> +}
> +#endif

huh?
g_nodes_free() frees ->children recursively and walks node->next!


---
ciaoTJ






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