jansson
jansson copied to clipboard
More flexible custom memory allocation
It'd be interesting to pass a user argument to custom allocation functions. For example:
void *my_malloc(size_t sz, void *userarg)
{
...
}
void my_free(void *p, void *userarg)
{
...
}
foo_t myarg;
json_set_alloc_funcs_arg(my_malloc, my_free, &myarg); //<---The wanted function
This way the custom functions would receive 'myarg' every time they were called. This is useful when using memory pool allocators such as Apache's mempools.
Thank you.
This is a good idea. Could you write the patch yourself?
I have never digged myself into jansson's code but yes, sure I can. How do you want me to send the patches?
I have submitted a pull request: https://github.com/akheron/jansson/pull/226