diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2011-05-09 08:55:35 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2011-05-09 08:55:35 +0000 |
commit | 99351cb0e3755a8685fcd5a40f298779f218a28c (patch) | |
tree | 0205dcd18ef7930ce3538c25919b8db97d65191e /epan/emem.h | |
parent | 3de2b1be7405adac31bd796f3380b9d8edbe0f99 (diff) |
Initial commit of slab allocator (sl_* API)
svn path=/trunk/; revision=37027
Diffstat (limited to 'epan/emem.h')
-rw-r--r-- | epan/emem.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/epan/emem.h b/epan/emem.h index 82f281ed1b..f082106f21 100644 --- a/epan/emem.h +++ b/epan/emem.h @@ -161,8 +161,30 @@ gchar* se_strdup_printf(const gchar* fmt, ...) /** release all memory allocated */ void se_free_all(void); +/************************************************************** + * slab allocator + **************************************************************/ +struct _emem_chunk_t; +/* Macros to initialize ws_memory_slab */ +/* XXX, is G_MEM_ALIGN enough? http://mail.gnome.org/archives/gtk-devel-list/2004-December/msg00091.html */ +#define WS_MEMORY_SLAB_INIT(type, count) { ((sizeof(type) + (G_MEM_ALIGN - 1)) & ~(G_MEM_ALIGN - 1)), count, NULL, NULL } +#define WS_MEMORY_SLAB_INIT_UNALIGNED(size, count) { size, count, NULL, NULL } +struct ws_memory_slab { + const gint item_size; + const gint count; + + struct _emem_chunk_t *chunk_list; + void *freed; +}; + +void *sl_alloc(struct ws_memory_slab *mem_chunk); +void *sl_alloc0(struct ws_memory_slab *mem_chunk); +void sl_free(struct ws_memory_slab *mem_chunk, gpointer ptr); + +/** release all memory allocated */ +void sl_free_all(struct ws_memory_slab *mem_chunk); /************************************************************** * binary trees |