Index: libedataserver/e-memory.c =================================================================== RCS file: /cvs/gnome/evolution-data-server/libedataserver/e-memory.c,v retrieving revision 1.6 diff -u -p -r1.6 e-memory.c --- libedataserver/e-memory.c 31 Aug 2005 04:26:10 -0000 1.6 +++ libedataserver/e-memory.c 21 Jun 2006 21:06:25 -0000 @@ -106,10 +106,15 @@ typedef struct _MemChunkFreeNode { } MemChunkFreeNode; typedef struct _EMemChunk { +#if 0 unsigned int blocksize; /* number of atoms in a block */ unsigned int atomsize; /* size of each atom */ GPtrArray *blocks; /* blocks of raw memory */ struct _MemChunkFreeNode *free; +#else + unsigned int atomsize; + GHashTable *atoms; +#endif } MemChunk; /** @@ -127,6 +132,7 @@ typedef struct _EMemChunk { **/ MemChunk *e_memchunk_new(int atomcount, int atomsize) { +#if 0 MemChunk *m = g_malloc(sizeof(*m)); m->blocksize = atomcount; @@ -135,6 +141,12 @@ MemChunk *e_memchunk_new(int atomcount, m->free = NULL; return m; +#else + MemChunk *m = g_slice_new (MemChunk); + m->atomsize = atomsize; + m->atoms = g_hash_table_new (g_direct_hash, g_direct_equal); + return m; +#endif } /** @@ -145,6 +157,7 @@ MemChunk *e_memchunk_new(int atomcount, **/ void *e_memchunk_alloc(MemChunk *m) { +#if 0 char *b; MemChunkFreeNode *f; void *mem; @@ -168,16 +181,30 @@ void *e_memchunk_alloc(MemChunk *m) m->free = f; return b; } +#else + void *b; + + b = g_slice_alloc (m->atomsize); + g_hash_table_insert (m->atoms, b, b); + return b; +#endif } void *e_memchunk_alloc0(EMemChunk *m) { +#if 0 void *mem; mem = e_memchunk_alloc(m); memset(mem, 0, m->atomsize); return mem; +#else + void *b; + b = g_slice_alloc0 (m->atomsize); + g_hash_table_insert (m->atoms, b, b); + return b; +#endif } /** @@ -191,6 +218,7 @@ void *e_memchunk_alloc0(EMemChunk *m) void e_memchunk_free(MemChunk *m, void *mem) { +#if 0 MemChunkFreeNode *f; /* put the location back in the free list. If we knew if the preceeding or following @@ -204,6 +232,20 @@ e_memchunk_free(MemChunk *m, void *mem) probably improve the locality of reference properties for the allocator */ /* and it would simplify some other algorithms at that, but slow this one down significantly */ +#else + g_hash_table_remove (m->atoms, mem); + g_slice_free1 (m->atomsize, mem); +#endif +} + +static gboolean +memchunk_foreach_free_atom_fn (gpointer key, gpointer value, gpointer user_data) +{ + MemChunk *m; + + m = user_data; + g_slice_free1 (m->atomsize, key); + return TRUE; } /** @@ -217,6 +259,7 @@ e_memchunk_free(MemChunk *m, void *mem) void e_memchunk_empty(MemChunk *m) { +#if 0 int i; MemChunkFreeNode *f, *h = NULL; @@ -227,6 +270,9 @@ e_memchunk_empty(MemChunk *m) h = f; } m->free = h; +#else + g_hash_table_foreach_remove (m->atoms, memchunk_foreach_free_atom_fn, m); +#endif } struct _cleaninfo { @@ -269,6 +315,7 @@ static int tree_search(struct _cleaninfo void e_memchunk_clean(MemChunk *m) { +#if 0 GTree *tree; int i; MemChunkFreeNode *f; @@ -329,6 +376,7 @@ e_memchunk_clean(MemChunk *m) } g_tree_destroy(tree); +#endif } /** @@ -340,6 +388,7 @@ e_memchunk_clean(MemChunk *m) void e_memchunk_destroy(MemChunk *m) { +#if 0 int i; if (m == NULL) @@ -349,6 +398,10 @@ e_memchunk_destroy(MemChunk *m) g_free(m->blocks->pdata[i]); g_ptr_array_free(m->blocks, TRUE); g_free(m); +#else + e_memchunk_clean (m); + g_slice_free (MemChunk, m); +#endif } typedef struct _MemPoolNode { @@ -364,11 +417,15 @@ typedef struct _MemPoolThresholdNode { #define ALIGNED_SIZEOF(t) ((sizeof (t) + G_MEM_ALIGN - 1) & -G_MEM_ALIGN) typedef struct _EMemPool { +#if 0 int blocksize; int threshold; unsigned int align; struct _MemPoolNode *blocks; struct _MemPoolThresholdNode *threshold_blocks; +#else + GHashTable *blocks; +#endif } MemPool; /* a pool of mempool header blocks */ @@ -401,6 +458,7 @@ static GStaticMutex mempool_mutex = G_ST **/ MemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags) { +#if 0 MemPool *pool; #ifdef G_THREADS_ENABLED @@ -432,6 +490,13 @@ MemPool *e_mempool_new(int blocksize, in pool->align = 1-1; } return pool; +#else + EMemPool *pool; + + pool = g_slice_new (MemPool); + pool->blocks = g_hash_table_new (g_direct_hash, g_direct_equal); + return pool; +#endif } /** @@ -445,6 +510,7 @@ MemPool *e_mempool_new(int blocksize, in **/ void *e_mempool_alloc(MemPool *pool, register int size) { +#if 0 size = (size + pool->align) & (~(pool->align)); if (size>=pool->threshold) { MemPoolThresholdNode *n; @@ -471,6 +537,12 @@ void *e_mempool_alloc(MemPool *pool, reg n->free = pool->blocksize - size; return (char *) n + ALIGNED_SIZEOF(*n) + n->free; } +#else + void *b; + b = g_slice_alloc (size); + g_hash_table_insert (pool->blocks, b, GSIZE_TO_POINTER (size)); + return b; +#endif } char *e_mempool_strdup(EMemPool *pool, const char *str) @@ -483,6 +555,16 @@ char *e_mempool_strdup(EMemPool *pool, c return out; } +static gboolean +pool_foreach_free_block_fn (gpointer key, gpointer value, gpointer user_data) +{ + gsize size; + + size = GPOINTER_TO_SIZE (value); + g_slice_free1 (size, key); + return TRUE; +} + /** * e_mempool_flush: * @pool: @@ -496,6 +578,7 @@ char *e_mempool_strdup(EMemPool *pool, c **/ void e_mempool_flush(MemPool *pool, int freeall) { +#if 0 MemPoolThresholdNode *tn, *tw; MemPoolNode *pw, *pn; @@ -522,6 +605,9 @@ void e_mempool_flush(MemPool *pool, int pw = pw->next; } } +#else + g_hash_table_foreach_remove (pool->blocks, pool_foreach_free_block_fn, NULL); +#endif } /** @@ -533,6 +619,7 @@ void e_mempool_flush(MemPool *pool, int void e_mempool_destroy(MemPool *pool) { if (pool) { +#if 0 e_mempool_flush(pool, 1); #ifdef G_THREADS_ENABLED g_static_mutex_lock(&mempool_mutex); @@ -540,6 +627,10 @@ void e_mempool_destroy(MemPool *pool) e_memchunk_free(mempool_memchunk, pool); #ifdef G_THREADS_ENABLED g_static_mutex_unlock(&mempool_mutex); +#endif +#else + e_mempool_flush (pool, TRUE); + g_slice_free (MemPool, pool); #endif } }