diff --git a/Changes b/Changes index dda2450..9fc8b52 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for libev, a high-performance and full-featured event loop. - removed redundant 0-ptr check in ev_once. + - updated/extended ev_set_allocator documentation. 4.25 Fri Dec 21 07:49:20 CET 2018 - INCOMPATIBLE CHANGE: EV_THROW was renamed to EV_NOEXCEPT diff --git a/ev.pod b/ev.pod index 0462e40..928b7e7 100644 --- a/ev.pod +++ b/ev.pod @@ -267,12 +267,32 @@ You could override this function in high-availability programs to, say, free some memory if it cannot allocate memory, to use a special allocator, or even to sleep a while and retry until some memory is available. +Example: The following is the C function that libev itself uses +which should work with C and C functions of all kinds and +is probably a good basis for your own implementation. + + static void * + ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT + { + if (size) + return realloc (ptr, size); + + free (ptr); + return 0; + } + Example: Replace the libev allocator with one that waits a bit and then -retries (example requires a standards-compliant C). +retries. static void * persistent_realloc (void *ptr, size_t size) { + if (!size) + { + free (ptr); + return 0; + } + for (;;) { void *newptr = realloc (ptr, size);