第三方库设置内存管理函数hooks(libevent curl openssl protobuf-c sqlite)

本文介绍了如何为libevent, libcurl, openssl, protobuf-c 和 sqlite3等第三方库设置内存管理函数hooks,包括libevent的event_set_mem_functions,libcurl的curl_global_init_mem以及sqlite3的内存分配接口。强调了在设置这些函数时需要注意的事项,如在使用libevent前设置,确保回调函数线程安全等。" 24692911,3011937,理解与应用:银行家算法,"['操作系统', '并发控制', '死锁', '资源管理']
摘要由CSDN通过智能技术生成

第三方库设置内存管理函数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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值