第三方库设置内存管理函数hooks(libevent curl openssl protobuf-c sqlite)
libevent
void event_set_mem_functions(void *(*malloc_fn)(size_t sz),
void *(*realloc_fn)(void *ptr, size_t sz),
void (*free_fn)(void *ptr));
Override the functions that Libevent uses for memory management.
Usually, Libevent uses the standard libc functions malloc, realloc, and free to allocate memory. Passing replacements for those functions to event_set_mem_functions() overrides this behavior.
Note that all memory returned from Libevent will be allocated by the replacement functions rather than by malloc() and realloc(). Thus, if you have replaced those functions, it will not be appropriate to free() memory that you get from Libevent. Instead, you must use the free_fn replacement that you provided.
Note also that if you are going to call this function, you should do so before any call to any Libevent function that does allocation. Otherwise, those funtions will allocate their memory using malloc(), but then later free it using your provided free_fn.
Parameters
malloc_fn | A replacement for malloc. |
---|---|
realloc_fn | A replacement for realloc |
free_fn | A replacement for free. |
/*Set the memory-management function hooks
Override the functions that libevent uses for memory management.
Usually, libevent uses the standard libc functions malloc, realloc, and free to allocate memory.
Passing replacements for those functions to event_set_mem_functions() overrides