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,%d)", elem->value, (int)(base_mallocator-elem)/(int)sizeof(int));
35 int main(int argc, char**argv)
37 xbt_mallocator_initialization_is_done(1);
39 xbt_mallocator_t mallocator =
40 xbt_mallocator_new(65536, element_mallocator_new_f, element_mallocator_free_f, element_mallocator_reset_f);
41 xbt_dynar_t elems = xbt_dynar_new(sizeof(element_t), NULL);
42 element_t elem = NULL;
43 base_mallocator = xbt_mallocator_get(mallocator);
45 for (i=0; i<=10; i++) {
46 elem = xbt_mallocator_get(mallocator);
48 xbt_dynar_push(elems, &elem);
52 for (i=0; i<=5; i++) {
53 xbt_dynar_pop(elems, &elem);
54 xbt_mallocator_release(mallocator, elem);
58 xbt_dynar_remove_at(elems, 2, &elem);
59 xbt_mallocator_release(mallocator, elem);
62 for (i=11; i<=15; i++) {
63 elem = xbt_mallocator_get(mallocator);
65 xbt_dynar_push(elems, &elem);