glouw / ctl

The C Template Library
MIT License
1.08k stars 55 forks source link

Custom memory allocators #14

Open atticus5 opened 3 years ago

atticus5 commented 3 years ago

Would like to also have the ability to define a custom memory allocator as we do for free and copy functions.

glouw commented 3 years ago

Yes, all memory allocations are defined with malloc, so just override malloc with your own call. Remember to revert the malloc redef at the end. This can be done on a per container basis, so it's pretty useful!

void* my_malloc(size_t size) { .... }
#define malloc my_malloc
#define P
#define T int
#include <vec.h>
#undef my_malloc
atticus5 commented 3 years ago

@glouw but can't do the same for free unfortunatelly, cause it is used as a suffix, unless I change it