diff options
author | Evan Huus <eapache@gmail.com> | 2013-05-22 15:42:12 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-05-22 15:42:12 +0000 |
commit | 5426ba4e027326d7b5bea08fd1bb8cfab0847c76 (patch) | |
tree | 16147df109ecbdf895d72ea44cf10462f2e38933 /epan/wmem/wmem_allocator_simple.c | |
parent | a2f6822feab6985a3b097dec62de3691ae6d57d6 (diff) |
Minor refactor: make the framework responsible for allocating and freeing the
actual wmem_allocator_t structure. This simplifies the internal API and
deduplicates a few alloc/free calls in the individual allocator implementations.
I'd originally made the allocators responsible for this on purpose with the
idea that they'd be able to optimize something clever based on the type of
allocator, but that's clearly more work and complexity than it's worth given
the small number of allocators we create/destroy.
svn path=/trunk/; revision=49512
Diffstat (limited to 'epan/wmem/wmem_allocator_simple.c')
-rw-r--r-- | epan/wmem/wmem_allocator_simple.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/epan/wmem/wmem_allocator_simple.c b/epan/wmem/wmem_allocator_simple.c index db43310b47..c08abb0dee 100644 --- a/epan/wmem/wmem_allocator_simple.c +++ b/epan/wmem/wmem_allocator_simple.c @@ -111,40 +111,35 @@ wmem_simple_gc(void *private_data _U_) } static void -wmem_simple_allocator_destroy(wmem_allocator_t *allocator) +wmem_simple_allocator_cleanup(void *private_data) { - wmem_simple_allocator_t *private_allocator; + wmem_simple_allocator_t *allocator; - private_allocator = (wmem_simple_allocator_t*) allocator->private_data; + allocator = (wmem_simple_allocator_t*) private_data; - g_hash_table_destroy(private_allocator->block_table); - g_slice_free(wmem_simple_allocator_t, private_allocator); - g_slice_free(wmem_allocator_t, allocator); + g_hash_table_destroy(allocator->block_table); + g_slice_free(wmem_simple_allocator_t, allocator); } -wmem_allocator_t * -wmem_simple_allocator_new(void) +void +wmem_simple_allocator_init(wmem_allocator_t *allocator) { - wmem_allocator_t *allocator; wmem_simple_allocator_t *simple_allocator; - allocator = g_slice_new(wmem_allocator_t); simple_allocator = g_slice_new(wmem_simple_allocator_t); - allocator->private_data = (void*) simple_allocator; - allocator->alloc = &wmem_simple_alloc; allocator->realloc = &wmem_simple_realloc; allocator->free = &wmem_simple_free; allocator->free_all = &wmem_simple_free_all; allocator->gc = &wmem_simple_gc; - allocator->destroy = &wmem_simple_allocator_destroy; + allocator->cleanup = &wmem_simple_allocator_cleanup; + + allocator->private_data = (void*) simple_allocator; simple_allocator->block_table = g_hash_table_new_full( &g_direct_hash, &g_direct_equal, NULL, &g_free); - - return allocator; } /* |