7 #define obj_pool_gen(pre, obj_t, initial_capacity) \
12 } pre##_pool = { 0, 0, NULL}; \
13 static uint32_t pre##_alloc(uint32_t count) \
16 while (pre##_pool.size + count > pre##_pool.capacity) { \
17 if (pre##_pool.capacity) { \
18 pre##_pool.capacity *= 2; \
20 pre##_pool.capacity = initial_capacity; \
23 realloc(pre##_pool.base, pre##_pool.capacity * sizeof(obj_t)); \
25 offset = pre##_pool.size; \
26 pre##_pool.size += count; \
29 static void pre##_free(uint32_t count) \
31 pre##_pool.size -= count; \
33 static uint32_t pre##_offset(obj_t * obj) \
35 return obj == NULL ? ~0 : obj - pre##_pool.base; \
37 static obj_t *pre##_pointer(uint32_t offset) \
39 return offset >= pre##_pool.size ? NULL : &pre##_pool.base[offset]; \