[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] Memory management
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] Memory management
- From: Bruno Avila <brunotavila@xxxxxxxxx>
- Date: Thu, 25 Oct 2012 15:21:09 -0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Thu, 25 Oct 2012 14:21:13 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Lnm8RUMWb1lx3ril4Ql21WyYKZHPJOa+l1xXqSGHw3I=; b=oTOudO1N102fDLj6fYvvyUIi5UcpWrwSR6tBL5Ph+afbgrj6XhGxvGiYyV44xxUHOC 4XZPyWkDS58KrMJgPbLtdisiDHZL//ETefxIvVJ23B1DYSLoYXr6wQcOMMN53RoJmdCi 1/zmrDh2JDKwLiGG6SblGjNcxZfuFcX2xSp6pvyH3HEaRgmYDc/KaRiMGNnn6VUdmlny CZoFWmvgUTj9JoPqdS2HA+DSHW9sODJqiBW8vuw4xGvenPQ9a4SFDLzd/S5WQJocqsQr yooCYvPAHyB2anLTgGU7Ca+9CYw+hyZfeNpVyYJAurj4rvFpvGXa1P+ooy7jGhcdiCmP jUIA==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
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?
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.
Best regards,
Bruno