ctl icon indicating copy to clipboard operation
ctl copied to clipboard

Custom memory allocators

Open atticus5 opened this issue 4 years ago • 2 comments

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

atticus5 avatar Jul 26 '21 20:07 atticus5

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

glouw avatar Aug 06 '21 18:08 glouw

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

atticus5 avatar Aug 08 '21 19:08 atticus5