… | |
… | |
115 | C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for |
115 | C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for |
116 | recommended ones. |
116 | recommended ones. |
117 | |
117 | |
118 | See the description of C<ev_embed> watchers for more info. |
118 | See the description of C<ev_embed> watchers for more info. |
119 | |
119 | |
120 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) |
120 | =item ev_set_allocator (void *(*cb)(void *ptr, size_t size)) |
121 | |
121 | |
122 | Sets the allocation function to use (the prototype is similar to the |
122 | Sets the allocation function to use (the prototype and semantics are |
123 | realloc C function, the semantics are identical). It is used to allocate |
123 | identical to the realloc C function). It is used to allocate and free |
124 | and free memory (no surprises here). If it returns zero when memory |
124 | memory (no surprises here). If it returns zero when memory needs to be |
125 | needs to be allocated, the library might abort or take some potentially |
125 | allocated, the library might abort or take some potentially destructive |
126 | destructive action. The default is your system realloc function. |
126 | action. The default is your system realloc function. |
127 | |
127 | |
128 | You could override this function in high-availability programs to, say, |
128 | You could override this function in high-availability programs to, say, |
129 | free some memory if it cannot allocate memory, to use a special allocator, |
129 | free some memory if it cannot allocate memory, to use a special allocator, |
130 | or even to sleep a while and retry until some memory is available. |
130 | or even to sleep a while and retry until some memory is available. |
131 | |
131 | |
132 | Example: replace the libev allocator with one that waits a bit and then |
132 | Example: replace the libev allocator with one that waits a bit and then |
133 | retries: better than mine). |
133 | retries: better than mine). |
134 | |
134 | |
135 | static void * |
135 | static void * |
136 | persistent_realloc (void *ptr, long size) |
136 | persistent_realloc (void *ptr, size_t size) |
137 | { |
137 | { |
138 | for (;;) |
138 | for (;;) |
139 | { |
139 | { |
140 | void *newptr = realloc (ptr, size); |
140 | void *newptr = realloc (ptr, size); |
141 | |
141 | |