[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Memory management



On Thu, Oct 25, 2012 at 2:21 PM, Bruno Avila <brunotavila@xxxxxxxxx> wrote:
> Hi all.
>
> I have a few questions about the memory management of libevent.
>
> 1) I replaced the memory functions of libvevent using
> event_set_mem_functions() with my own functions and I added a counter for
> malloc, realloc and free (Yes, I implemented the special cases realloc(NULL,
> size) and realloc(ptr, 0)). In my http client, while it is downloading
> webpages, I noticed that the number of allocations only increases. It stops
> growing for a while, but then it starts growing up again. When I stop the
> downloads and execute event_free(base), valgrind shows no memory leak. I
> believe that the memory is freed only at the end. The problem is that my
> crawler should never stop downloading and, therefore, the memory usage will
> always increase.
>      a) How can I control the memory usage in libevent?
>      b) I also notice that I can't free a http request, only a http
> connection. Isn't that the cause of freeing memory being defer?

What allocations seem to be kicking around too long, or growing
without bounds?  I don't *think* there should be any
grows-without-bounds stuff in evhttp.  Are you able to tell where the
memory in question is getting allocated?

> 2) Suggestion: make event_set_mem_functions() thread-safe. Libz uses a
> parameter "void* opaque" that allows client applications to pass a custom
> data structure to their custom memory functions. Please copy them :).
> Otherwise, I have to use locks in a multithread application, which greatly
> drops my performance.

That's a fine idea; it would need to be a new interface, of course, so
that existing users of event_set_mem_functions() won't break.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.