… | |
… | |
240 | might be supported on the current system, you would need to look at |
240 | might be supported on the current system, you would need to look at |
241 | \&\f(CW\*(C`ev_embeddable_backends () & ev_supported_backends ()\*(C'\fR, likewise for |
241 | \&\f(CW\*(C`ev_embeddable_backends () & ev_supported_backends ()\*(C'\fR, likewise for |
242 | recommended ones. |
242 | recommended ones. |
243 | .Sp |
243 | .Sp |
244 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
244 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
245 | .IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 |
245 | .IP "ev_set_allocator (void *(*cb)(void *ptr, size_t size))" 4 |
246 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" |
246 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, size_t size))" |
247 | Sets the allocation function to use (the prototype is similar to the |
247 | Sets the allocation function to use (the prototype and semantics are |
248 | realloc C function, the semantics are identical). It is used to allocate |
248 | identical to the realloc C function). It is used to allocate and free |
249 | and free memory (no surprises here). If it returns zero when memory |
249 | memory (no surprises here). If it returns zero when memory needs to be |
250 | needs to be allocated, the library might abort or take some potentially |
250 | allocated, the library might abort or take some potentially destructive |
251 | destructive action. The default is your system realloc function. |
251 | action. The default is your system realloc function. |
252 | .Sp |
252 | .Sp |
253 | You could override this function in high-availability programs to, say, |
253 | You could override this function in high-availability programs to, say, |
254 | free some memory if it cannot allocate memory, to use a special allocator, |
254 | free some memory if it cannot allocate memory, to use a special allocator, |
255 | or even to sleep a while and retry until some memory is available. |
255 | or even to sleep a while and retry until some memory is available. |
256 | .Sp |
256 | .Sp |
257 | Example: replace the libev allocator with one that waits a bit and then |
257 | Example: replace the libev allocator with one that waits a bit and then |
258 | retries: better than mine). |
258 | retries: better than mine). |
259 | .Sp |
259 | .Sp |
260 | .Vb 6 |
260 | .Vb 6 |
261 | \& static void * |
261 | \& static void * |
262 | \& persistent_realloc (void *ptr, long size) |
262 | \& persistent_realloc (void *ptr, size_t size) |
263 | \& { |
263 | \& { |
264 | \& for (;;) |
264 | \& for (;;) |
265 | \& { |
265 | \& { |
266 | \& void *newptr = realloc (ptr, size); |
266 | \& void *newptr = realloc (ptr, size); |
267 | .Ve |
267 | .Ve |