librdkafka icon indicating copy to clipboard operation
librdkafka copied to clipboard

Add API to replace rd_kafka's default allocator

Open sarkanyi opened this issue 6 years ago • 8 comments
trafficstars

Add API to replace rd_kafka's default allocator with a custom implementation

sarkanyi avatar Jul 11 '19 12:07 sarkanyi

I think I covered all requests. Could you please re-check and merge if ok? Also please check and merge: https://github.com/edenhill/librdkafka/pull/2405 because it's related. I can rebase both if needed

sarkanyi avatar Jul 17 '19 08:07 sarkanyi

Will re-review soon, but this will not be merged until after the next release.

edenhill avatar Jul 17 '19 09:07 edenhill

With your PR merged to add mem_malloc() et.al. I'm guessing this PR is no longer needed, an application can use LD_PRELOAD.. to replace the rd_malloc()* calls, right?

edenhill avatar Mar 25 '21 08:03 edenhill

With your PR merged to add mem_malloc() et.al. I'm guessing this PR is no longer needed, an application can use LD_PRELOAD.. to replace the rd_malloc()* calls, right?

To be honest it would be preferable to have an API, either this - I'll change to have rd_str_dup & co also added, or function hooks something like: "typeof (&rd_malloc) malloc_fn = rd_malloc_hook ? rd_malloc_hook : malloc; void *p = malloc_fn(sz);" -set via a setter function?

sarkanyi avatar Mar 25 '21 09:03 sarkanyi

Most big libraries use some sort of API to set the custom allocator, ie: jansson has void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn), it makes it more explicit. LD_PRELOAD is quite invasive, even if we'd overload rd_funcs

sarkanyi avatar Mar 25 '21 09:03 sarkanyi

Okay, a single function to set the allocators once on program startup before calling any other librdkafka function (in particular before global_init is called) should be fine and avoid the need for locking.

edenhill avatar Apr 06 '21 14:04 edenhill

Hi, is this still on track for 1.8? Do you need me to do anything else on it?

sarkanyi avatar Jul 20 '21 06:07 sarkanyi

@edenhill won't this change make it into 1.9.0? Thanks

sarkanyi avatar Apr 26 '22 06:04 sarkanyi

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] avatar Aug 21 '23 15:08 cla-assistant[bot]