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_block.c | |
parent | a2f6822feab6985a3b097dec62de3691ae6d57d6 (diff) | |
download | wireshark-5426ba4e027326d7b5bea08fd1bb8cfab0847c76.tar.gz |
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_block.c')
-rw-r--r-- | epan/wmem/wmem_allocator_block.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/epan/wmem/wmem_allocator_block.c b/epan/wmem/wmem_allocator_block.c index f31a898328..da64eee7ea 100644 --- a/epan/wmem/wmem_allocator_block.c +++ b/epan/wmem/wmem_allocator_block.c @@ -853,45 +853,36 @@ wmem_block_gc(void *private_data) } static void -wmem_block_allocator_destroy(wmem_allocator_t *allocator) +wmem_block_allocator_cleanup(void *private_data) { - wmem_block_allocator_t *real_allocator; - - real_allocator = (wmem_block_allocator_t*) allocator->private_data; - /* wmem guarantees that free_all() is called directly before this, so * calling gc will return all our blocks to the OS automatically */ - wmem_block_gc(real_allocator); + wmem_block_gc(private_data); /* then just free the allocator structs */ - g_slice_free(wmem_block_allocator_t, real_allocator); - g_slice_free(wmem_allocator_t, allocator); + g_slice_free(wmem_block_allocator_t, private_data); } -wmem_allocator_t * -wmem_block_allocator_new(void) +void +wmem_block_allocator_init(wmem_allocator_t *allocator) { - wmem_allocator_t *allocator; wmem_block_allocator_t *block_allocator; - allocator = g_slice_new(wmem_allocator_t); block_allocator = g_slice_new(wmem_block_allocator_t); - allocator->private_data = (void*) block_allocator; - allocator->alloc = &wmem_block_alloc; allocator->realloc = &wmem_block_realloc; allocator->free = &wmem_block_free; allocator->free_all = &wmem_block_free_all; allocator->gc = &wmem_block_gc; - allocator->destroy = &wmem_block_allocator_destroy; + allocator->cleanup = &wmem_block_allocator_cleanup; + + allocator->private_data = (void*) block_allocator; block_allocator->block_list = NULL; block_allocator->free_list_head = NULL; block_allocator->free_insert_point = NULL; - - return allocator; } /* |