[getdns-api] user defined allocators

Willem Toorop willem at nlnetlabs.nl
Fri Sep 20 14:25:28 CEST 2013


Op 21-08-13 13:04, Wiley, Glen schreef:
> As we are working on our implementation of the getdns API I realized 
> that there doesn't seem to be a way for the helper functions that 
> handle the dict and list types to get to the user defined allocator. 
>  The allocator is specified in a context, however the signatures of 
> the helper functions do not accept a context as an argument.  There 
> are a few ways to address this:
>
>  1. Add a context as an argument to the helper functions.  This is
>     probably the least disruptive to the rest of the API.
>  2. Change the way a user defined allocator is defined.  It is likely
>     that the application developer would expect to use the same
>     allocator throughout the application so it may be enough to make
>     an assignment outside a context as an initialization step.
>
> I am sure that there are other options, but I think approach #2 would 
> be a comfortable way to handle this.
I agree.

Also the custom memory management functions that may be specified have 
the same prototype as the standard C functions.  This restricts the type 
of custom memory functions to ones that either do no custom memory 
bookkeeping, or have the needed bookkeeping-journal in globals.  Having 
global custom memory functions in a individual getdns context feels as a 
discrepancy.  A global registration function would suit better. For 
example, just like the one in libevent:

*void*  getdns_set_mem_functions(*void*  *(*malloc_fn)(size_t sz),
                               *void*  *(*realloc_fn)(*void*  *ptr, size_t sz),
                               *void*  (*free_fn)(*void*  *ptr));


I prefer custom memory management functions to be implementation 
specific in the API, just like setting the event base is.  I feel there 
are too many variables to consider to have a conclusive solution that 
fits all.  It would also allow for implementations to match this 
capability with the capabilities of the event base.


-- Willem


PS. An implementations that would allow bookkeeping memory functions, 
could have a registration function that would look something like this:

*void*  getdns_context_set_mem_functions(getdns_context_t*  *context*,
                                       void*  *(*malloc_fn)(*void*  *journal, size_t sz),
                               *         void*  *(*realloc_fn)(*void*  *journal,*void*  *ptr, size_t sz),
                               *         void*  (*free_fn)(*void*  *journal,*void*  *ptr));


Of course it would then also need custom list and dict create functions:

struct getdns_list * getdns_list_create_custom(getdns_context_t*  *context*);*

struct getdns_dict * getdns_dict_create_custom(getdns_context_t*  *context*);

*

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://getdnsapi.net/pipermail/spec/attachments/20130920/edbcf2cf/attachment.html>
-------------- next part --------------
_______________________________________________
getdns-api mailing list
getdns-api at vpnc.org


More information about the spec mailing list