2013-06-12
2013-06-12 20:04:24 by Arne Goedeke <el@laramies.com>
-
d4765935a98dfa784d1de64b83e61938bb534446
(20 lines)
(+14/-6)
[
Show
| Annotate
]
Branch: 7.9
Added new block allocator. It dramatically speeds up free, when
allocating many blocks and deallocation happens non linearly.
35:
#define PRE_INIT_BLOCK(X) X->free_func=(callback_func)remove_callback;
#endif
#endif
- BLOCK_ALLOC(callback, CALLBACK_CHUNK)
+
-
+ #include "block_allocator.h"
+ static struct block_allocator callback_allocator
+ = BA_INIT(sizeof(struct callback), CALLBACK_CHUNK);
-
+ void count_memory_in_callbacks(size_t * num, size_t * size) {
+ ba_count_all(&callback_allocator, num, size);
+ }
+
+
#ifdef PIKE_DEBUG
extern int d_flag;
53: Inside #if defined(PIKE_DEBUG) and #if 0
if ((bar->x <= c) && ((c - bar->x) < CALLBACK_CHUNK)) {
struct callback *foo;
for (foo = bar->free_callbacks; foo;
- foo = (void *)foo->BLOCK_ALLOC_NEXT) {
+ foo = (void *)foo->next) {
if (foo == c) return 1;
}
return 0;
191: Inside #if 0
l->free_func=(callback_func)remove_callback;
#endif
#endif
- really_free_callback(l);
+ ba_free(&callback_allocator, l);
}else{
ptr=& l->next;
}
206:
callback_func free_func)
{
struct callback *l;
- l=alloc_callback();
+ l=(struct callback*)ba_alloc(&callback_allocator);
l->call=call;
l->arg=arg;
l->free_func=free_func;
246:
if(l->free_func)
l->free_func(l, l->arg, 0);
*ptr=l->next;
- really_free_callback(l);
+ ba_free(&callback_allocator, l);
}
}
void cleanup_callbacks(void)
{
- free_all_callback_blocks();
+ ba_destroy(&callback_allocator);
}