1 #include "xbt/mallocator.h"
4 typedef struct element {
7 typedef struct element *element_t;
9 element_t base_mallocator;
11 static void *element_mallocator_new_f(void)
13 element_t elem = xbt_new(s_element_t, 1);
18 static void element_mallocator_free_f(void *elem)
23 #define element_mallocator_reset_f ((void_f_pvoid_t)NULL)
25 static void pprint_elems(xbt_dynar_t elems) {
29 xbt_dynar_foreach(elems, iter, elem) {
30 printf(" (%d,%ld)", elem->value, base_mallocator-elem);
35 int main(int argc, char**argv)
37 xbt_mallocator_initialization_is_done(1);
39 xbt_mallocator_t mallocator = xbt_mallocator_new(65536,
40 element_mallocator_new_f,
41 element_mallocator_free_f,
42 element_mallocator_reset_f);
43 xbt_dynar_t elems = xbt_dynar_new(sizeof(element_t), NULL);
44 element_t elem = NULL;
45 base_mallocator = xbt_mallocator_get(mallocator);
47 for (i=0; i<=10; i++) {
48 elem = xbt_mallocator_get(mallocator);
50 xbt_dynar_push(elems, &elem);
54 for (i=0; i<=5; i++) {
55 xbt_dynar_pop(elems, &elem);
56 xbt_mallocator_release(mallocator, elem);
60 xbt_dynar_remove_at(elems, 2, &elem);
61 xbt_mallocator_release(mallocator, elem);
64 for (i=11; i<=15; i++) {
65 elem = xbt_mallocator_get(mallocator);
67 xbt_dynar_push(elems, &elem);