best ways to do clean up

Juan Pablo L jpablolorenzetti at gmail.com
Wed Dec 29 04:19:58 CET 2010


thank you very much for your answer, you give me good ideas. i find libev to
be very efficient and useful but since i have no experience with other event
library other than glib i can not stop my self from trying to do same with
libev.

One thing sounds very interesting to me (although i m not sure what you mean
about this particular point and the document is not very clear about this)
since i m customizing an ev_async, in glib you create a custom watcher and
you can override the prepare and check functions (also the finalize
function) so when the loop loops it calls your prepare and check functions
for only this custom watcher without affecting the prepare/check/finalize
functions that may be in the same loop, is this possible with libev that is,
to customize the prepare and check functions only for particular watcher
without affecting the other watchers in the loop ??? i ask this because i
find this to be very useful to me.

On 28 December 2010 22:54, Marc Lehmann <schmorp at schmorp.de> wrote:

> On Tue, Dec 28, 2010 at 06:46:25PM -0400, Juan Pablo L <
> jpablolorenzetti at gmail.com> wrote:
> > What i m trying to do is a custom watcher, in glib you override the
> > check/prepare/dispatch and finilize so when the loop in glib is exiting
> > the loop itself would call the finalize function on all event sources
> > (watches in libev) automatically
>
> Sounds like a job for an ev_cleanup watcher, maybe, depending on what you
> mean with "loop exiting".
>
> in most cases, however, you can just call the finaliser functions you want
> yourself after exiting the loop.
>
> > but in libev you do not get to
> > customize the check/prepare/dispatch/finalize functions
>
> libev is actually much more customisable than glib in that respect, as you
> can build your own watchers from components (see ASSOCIATING CUSTOM DATA
> WITH A WATCHER in the docs, which also shows how to combine two functions
> into one custom watcher).
>
> glib doesn't allow for much customisation - you get one type of watcher,
> and that's it.
>
> > (although you can modify prepare and check but at the loop level and not
> > at the watcher level)
>
> check and prepare are at the loop level as well in glib - glib calls each
> single watcher (multiple times, even), while in libev, you can choose for
> which watchers this overhead is done, otherwise they work more or less
> identical (the API is different so libev can take advantage of advanced
> kernel interfaces, which glib cannot really do).
>
> my guess is that as soon as you have internalised this (and learned how
> to do it in practise :), you will be as comfortable with libev as you
> were with glib - and many more event loops, as most event loops work like
> libev, not like glib (for performance reasons).
>
> > so i m not sure what is the correct way to do this in libev, i saw a
> > ev_cleanup watcher , so the libev solution for cleaning up some memory
> used
> > for other watchers at the end of the loop
> > would be to register a watcher per watcher-to-clean so they do the
> cleaning
> > at the end?
>
> possibly - a lot depends on what you mean with cleanup.
>
> > just a clarification, i m making a server and i create a new
> > thread per connection and each thread has
> > its own loop so i can not leave the OS clean the memory as one loop
> > destroying does not mean the application is exiting, it means only one
> > client disconnecting. thanks!!!
>
> well, I'd say the solution to that is to just free all your data when
> ev_run returns/when your thread is about to end :) ev_cleanup can help
> with that, but libev doesn't manage your resources for you, you have to do
> that yourself.
>
> If the overhead doesn't concern you (it's still much lower than doing the
> equivalent with glib) you can simply add an ev_cleanup to each of your
> custom watcher structures and start it when the watcher is started.
>
> --
>                The choice of a       Deliantra, the free code+content MORPG
>      -----==-     _GNU_              http://www.deliantra.net
>      ----==-- _       generation
>      ---==---(_)__  __ ____  __      Marc Lehmann
>      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
>      -=====/_/_//_/\_,_/ /_/\_\
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20101228/75901c6d/attachment.html>


More information about the libev mailing list