jansson icon indicating copy to clipboard operation
jansson copied to clipboard

More flexible custom memory allocation

Open claudix opened this issue 10 years ago • 3 comments

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.

claudix avatar Mar 05 '15 08:03 claudix

This is a good idea. Could you write the patch yourself?

akheron avatar Mar 05 '15 08:03 akheron

I have never digged myself into jansson's code but yes, sure I can. How do you want me to send the patches?

claudix avatar Mar 05 '15 09:03 claudix

I have submitted a pull request: https://github.com/akheron/jansson/pull/226

claudix avatar Mar 05 '15 10:03 claudix