diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-11-25 17:14:19 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-11-25 17:14:19 +0000 |
commit | 7eb250e9c52813f30fef256b97f08a6871fd381a (patch) | |
tree | 434da79bcc882cb0d88a7db1ad71003b51aad091 /event.h | |
parent | 98b5453ecdd6a474ba8c3495285e607d5b7a8e57 (diff) | |
download | libevent-7eb250e9c52813f30fef256b97f08a6871fd381a.tar.gz |
r14939@tombo: nickm | 2007-11-25 11:59:26 -0500
New function event_set_mem_functions to replace internal calls to malloc, free, etc with a user-supplied functions.
svn:r541
Diffstat (limited to 'event.h')
-rw-r--r-- | event.h | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1105,6 +1105,27 @@ int evtag_unmarshal_string(struct evbuffer *evbuf, ev_uint8_t need_tag, int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint8_t need_tag, struct timeval *ptv); +/** + 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. To restore the default + behavior, pass NULLs as the arguments to this function. + + 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 may not be appropriate to free() memory + that you get from libevent. + + @param malloc_fn A replacement for malloc. + @param realloc_fn A replacement for realloc + @param free_fn A replacement for free. + **/ +void event_set_mem_functions(void *(*malloc_fn)(size_t sz), + void *(*realloc_fn)(void *ptr, size_t sz), + void (*free_fn)(void *ptr)); + #ifdef __cplusplus } #endif |