Add wmem_destroy_list, wmem_destroy_queue, wmem_destroy_stack so that those
data-structures can be used with manually managed memory. svn path=/trunk/; revision=54432
This commit is contained in:
parent
5f91a0afc7
commit
1dfa4e2697
|
@ -173,6 +173,22 @@ wmem_list_new(wmem_allocator_t *allocator)
|
|||
return list;
|
||||
}
|
||||
|
||||
void
|
||||
wmem_destroy_list(wmem_list_t *list)
|
||||
{
|
||||
wmem_list_frame_t *cur, *next;
|
||||
|
||||
cur = list->head;
|
||||
|
||||
while (cur) {
|
||||
next = cur->next;
|
||||
wmem_free(list->allocator, cur);
|
||||
cur = next;
|
||||
}
|
||||
|
||||
wmem_free(list->allocator, list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
|
|
|
@ -95,6 +95,10 @@ wmem_list_t *
|
|||
wmem_list_new(wmem_allocator_t *allocator)
|
||||
G_GNUC_MALLOC;
|
||||
|
||||
WS_DLL_PUBLIC
|
||||
void
|
||||
wmem_destroy_list(wmem_list_t *list);
|
||||
|
||||
/** @}
|
||||
* @} */
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ typedef wmem_list_t wmem_queue_t;
|
|||
|
||||
#define wmem_queue_new(ALLOCATOR) wmem_list_new(ALLOCATOR)
|
||||
|
||||
#define wmem_destroy_queue(QUEUE) wmem_destroy_list(QUEUE)
|
||||
|
||||
/** @}
|
||||
* @} */
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ wmem_stack_pop(wmem_stack_t *stack);
|
|||
|
||||
#define wmem_stack_new(ALLOCATOR) wmem_list_new(ALLOCATOR)
|
||||
|
||||
#define wmem_destroy_stack(STACK) wmem_destroy_list(STACK)
|
||||
|
||||
/** @}
|
||||
* @} */
|
||||
|
||||
|
|
|
@ -593,6 +593,13 @@ wmem_test_list(void)
|
|||
}
|
||||
|
||||
wmem_destroy_allocator(allocator);
|
||||
|
||||
list = wmem_list_new(NULL);
|
||||
for (i=0; i<CONTAINER_ITERS; i++) {
|
||||
wmem_list_prepend(list, GINT_TO_POINTER(i));
|
||||
}
|
||||
g_assert(wmem_list_count(list) == CONTAINER_ITERS);
|
||||
wmem_destroy_list(list);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -623,6 +630,8 @@ wmem_test_queue(void)
|
|||
}
|
||||
g_assert(wmem_queue_count(queue) == 0);
|
||||
|
||||
wmem_destroy_queue(queue);
|
||||
|
||||
wmem_destroy_allocator(allocator);
|
||||
}
|
||||
|
||||
|
@ -654,6 +663,8 @@ wmem_test_stack(void)
|
|||
}
|
||||
g_assert(wmem_stack_count(stack) == 0);
|
||||
|
||||
wmem_destroy_stack(stack);
|
||||
|
||||
wmem_destroy_allocator(allocator);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue