cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl_schannel.c and realloc()

From: Gisle Vanem <gvanem_at_broadpark.no>
Date: Tue, 12 Jun 2012 23:31:24 +0200

I've learned that using realloc() should be kept to a minimum;
they could cause copying memory from old to new buffer, heap
fragmentation etc. So, I noticed that the number of realloc() calls in
libcurl has risen sharply with USE_SCHANNEL. A small test using:
  curl -v https://www.google.com

results in:
  with OpenSSL, 4 realloc()
  with Schannel, 19 realloc().

I noticed that using -DCURLDEBUG and the nice code in
memdebug.c. From the trace:

  MEM curl_schannel.c:690 realloc(0x3e9520, 6144) = 0x3eb9e8
  MEM curl_schannel.c:690 realloc(0x3eb9e8, 8192) = 0x3eb9e8
  MEM curl_schannel.c:690 realloc(0x3eb9e8, 10240) = 0xb7b010
  MEM curl_schannel.c:690 realloc(0xb7b010, 12288) = 0xb7d828
  MEM curl_schannel.c:690 realloc(0xb7d828, 14336) = 0xb7d828
  MEM curl_schannel.c:690 realloc(0xb7d828, 16384) = 0xb7d828

So should the 'CURL_SCHANNEL_BUFFER_STEP_SIZE' (currently
2048) be increased to reduse these reallocs? A good practice is also
to increase the amount of memory twofold or estimate the required
amount beforehand. I'm not sure how easy this is in this case.

AFAICS, reducing realloc() could also reduce the # of memmove()s.

--gv

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-06-12