CRoaring team,
My team at IBM is using CRoaring as part of our project and required a custom memory management solution. As there is no way to do this currently, we implemented our own which we would like to contribute back to the community. There were a large number of widespread changes required to do this, which I will outline here.
The first change is the addition of a roaring_options_t struct that can be passed in as a pointer to a new variant of externals. For example, the existing roaring_bitmap_t * roaring_bitmap_create(void) function has a new roaring_bitmap_t * roaring_bitmap_create_with_opts(roaring_options_t *options) variant that accepts an options pointer.
The roaring_options_t struct is intended to be an extendable struct that is accessible and common at all levels of the bitmap. Currently, the roaring_bitmap_t owns the lifetime of this struct, and a pointer to its instance is passed down to the roaring_array_t, and all the containers therein. This option struct is entirely optional and can be set to null.
Within roaring_options_t there is another new struct, roaring_memory_t. This contains function pointers to memory management functions (malloc, free, etc.), and a void pointer that can be used by the caller to pass down additional inputs to these functions.
Finally, each call to the built-in memory management function that existed previously in the code has been replaced with shims, for example, void* roaring_malloc(roaring_options_t*, size_t), that consume the option struct. If the options are non-null, it will use the user-provided memory function, otherwise, it will use the built-ins.
The design of this code was intended to have the least external impact possible, meaning that for the most part, all tests of the externals have remained unchanged. Changes were required on some of the lower-level test cases, for example, the ones that created and manipulated containers directly.
If these changes will be beneficial to the CRoaring project (potentially with suggested modification to better conform to existing standards and best practices in the community), we would like to make them available for feedback. Please let us know your preferred method of doing so (i.e. public fork, pull request, etc).
Thanks,
Matt Olan