aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-09-08 15:18:55 +0000
committerEvan Huus <eapache@gmail.com>2013-09-08 15:18:55 +0000
commit5f7187c6588456464a8232a8d1c04fd9eeb9a914 (patch)
tree1e404f5dbb0a44a16a4e922a7f531219aee30c7d /epan/wmem
parent720935ca0474597998c6d9daf1e46d1034ae956c (diff)
Cycle the recycler in realloc() and free() as well, reducing memory usage of the
stress-test by another ~10%. svn path=/trunk/; revision=51840
Diffstat (limited to 'epan/wmem')
-rw-r--r--epan/wmem/wmem_allocator_block.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/epan/wmem/wmem_allocator_block.c b/epan/wmem/wmem_allocator_block.c
index 18a8edb111..da9a58f552 100644
--- a/epan/wmem/wmem_allocator_block.c
+++ b/epan/wmem/wmem_allocator_block.c
@@ -376,6 +376,10 @@ wmem_block_cycle_recycler(wmem_block_allocator_t *allocator)
chunk = allocator->recycler_head;
+ if (chunk == NULL) {
+ return;
+ }
+
free_chunk = WMEM_GET_FREE(chunk);
if (free_chunk->next->len < chunk->len) {
@@ -915,9 +919,7 @@ wmem_block_alloc(void *private_data, const size_t size)
g_assert(chunk != allocator->recycler_head);
/* Now cycle the recycler */
- if (allocator->recycler_head) {
- wmem_block_cycle_recycler(allocator);
- }
+ wmem_block_cycle_recycler(allocator);
/* mark it as used */
chunk->used = TRUE;
@@ -947,6 +949,9 @@ wmem_block_free(void *private_data, void *ptr)
/* merge it with any other free chunks adjacent to it, so that contiguous
* free space doesn't get fragmented */
wmem_block_merge_free(allocator, chunk);
+
+ /* Now cycle the recycler */
+ wmem_block_cycle_recycler(allocator);
}
static void *
@@ -1004,6 +1009,9 @@ wmem_block_realloc(void *private_data, void *ptr, const size_t size)
tmp->prev = chunk->len;
}
+ /* Now cycle the recycler */
+ wmem_block_cycle_recycler(allocator);
+
/* And return the same old pointer */
return ptr;
}
@@ -1015,6 +1023,9 @@ wmem_block_realloc(void *private_data, void *ptr, const size_t size)
memcpy(newptr, ptr, WMEM_CHUNK_DATA_LEN(chunk));
wmem_block_free(private_data, ptr);
+ /* No need to cycle the recycler, alloc and free both did that
+ * already */
+
return newptr;
}
}
@@ -1022,6 +1033,9 @@ wmem_block_realloc(void *private_data, void *ptr, const size_t size)
/* shrink */
wmem_block_split_used_chunk(allocator, chunk, size);
+ /* Now cycle the recycler */
+ wmem_block_cycle_recycler(allocator);
+
return ptr;
}