Custom data type with a time watcher and memory control at process exit.
vvvua
vvvua at lost.in.ua
Thu Oct 21 16:13:46 CEST 2010
Sorry for the delay :), I was busy with other part of the project and
had to read documentation of libev before answering you.
Thanks for the reply.
>> The process is shutting down in 2 min after program starts.
>> I have to cancel watchers, destroy the loop and free memory.
>>
> If the process itself is shutting down (exiting?) then freeing the
> watchers is just wasting cpu cycles, the OS does it for you, and much
> faster.
>
I know that but parent process isn't OS.
So the right way is:
1) To store list of pointers to watchers.
2) When the callback rises, delete the pointer from the list and free
memory.
3) At the end of the process free memory with help of list.
On 14.10.2010 07:00, Marc Lehmann wrote:
> On Fri, Oct 08, 2010 at 11:33:05AM +0300, vvvua<vvvua at lost.in.ua> wrote:
>
>>> Or maybe your goal is something else?
>>>
>>>
>> I don't have a list of pointers to watchers. Each watcher frees
>> memory when callback function is invoked.
>> So I have two ways to free memory:
>> 1) Create a list of pointers and free all memory manually when
>> destroying a loop.
>> 2) Generate events that invoke all registered callbacks using libev.
>>
>> Is the second way possible? I understand, that libev doesn't free
>> memory allocated by user.
>>
> Sorry for the delay..
>
> But yes, you can generate events for all registered watchers, _as long as you
> keep the list of registered watchers yourself_, by either using ev_invoke or
> ev_feed_event.
>
> You could e.g. use EV_CUSTOM as a flag for the callback(s) to free the
> memory. You could, of course also just free it yourself, or call the
> callback yourself.
>
> Keep in mind that libev itself might register events, or other parts of
> your program, so even if libev had a list, it wouldn't be very helpful.
>
>
>> The process is shutting down in 2 min after program starts.
>> I have to cancel watchers, destroy the loop and free memory.
>>
> If the process itself is shutting down (exiting?) then freeing the
> watchers is just wasting cpu cycles, the OS does it for you, and much
> faster.
>
>
More information about the libev
mailing list