diff options
author | Daniel Stenberg <daniel@haxx.se> | 2013-04-26 22:23:08 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2013-04-26 22:55:55 +0200 |
commit | 642067287931da64e485e402e5e1fa5096abcddd (patch) | |
tree | f1c843b46447d2e4607bfe029823352932c4d01f /lib/multi.c | |
parent | c4067a5678321b1755f6027a5c7510b17e7c16a6 (diff) |
curl_easy_init: use less mallocs
By introducing an internal alternative to curl_multi_init() that accepts
parameters to set the hash sizes, easy handles will now use tiny socket
and connection hash tables since it will only ever add a single easy
handle to that multi handle.
This decreased the number mallocs in test 40 (which is a rather simple
and typical easy interface use case) from 1142 to 138. The maximum
amount of memory allocated used went down from 118969 to 78805.
Diffstat (limited to 'lib/multi.c')
-rw-r--r-- | lib/multi.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/multi.c b/lib/multi.c index 7d795cf3d..77262fc34 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -58,6 +58,7 @@ #define CURL_SOCKET_HASH_TABLE_SIZE 911 #endif +#define CURL_CONNECTION_HASH_SIZE 97 #define CURL_MULTI_HANDLE 0x000bab1e @@ -246,9 +247,9 @@ static size_t hash_fd(void *key, size_t key_length, size_t slots_num) * per call." * */ -static struct curl_hash *sh_init(void) +static struct curl_hash *sh_init(int hashsize) { - return Curl_hash_alloc(CURL_SOCKET_HASH_TABLE_SIZE, hash_fd, fd_key_compare, + return Curl_hash_alloc(hashsize, hash_fd, fd_key_compare, sh_freeentry); } @@ -278,7 +279,8 @@ static void multi_freeamsg(void *a, void *b) (void)b; } -CURLM *curl_multi_init(void) +struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */ + int chashsize) /* connection hash */ { struct Curl_multi *multi = calloc(1, sizeof(struct Curl_multi)); @@ -291,11 +293,11 @@ CURLM *curl_multi_init(void) if(!multi->hostcache) goto error; - multi->sockhash = sh_init(); + multi->sockhash = sh_init(hashsize); if(!multi->sockhash) goto error; - multi->conn_cache = Curl_conncache_init(); + multi->conn_cache = Curl_conncache_init(chashsize); if(!multi->conn_cache) goto error; @@ -325,6 +327,13 @@ CURLM *curl_multi_init(void) return NULL; } +CURLM *curl_multi_init(void) +{ + return Curl_multi_handle(CURL_SOCKET_HASH_TABLE_SIZE, + CURL_CONNECTION_HASH_SIZE); +} + + CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *easy_handle) { |