curl-library
Re: curl_schannel.c and realloc()
Date: Wed, 13 Jun 2012 11:48:49 +0200 (CEST)
On Wed, 13 Jun 2012, Marc Hoersken wrote:
> If this is the case, we can probably just set CURL_SCHANNEL_BUFFER_INIT_SIZE
> to BUFSIZE in order to reduce the number of realloc() calls. I would
> personally keep the code to gracefully handle the need for more buffer
> space.
I was first going to agree and then a second thought struck me. Why would it
ever need to handle more data? If it gets called asking for 20K of data,
there's nothing in the API that says the function must return that much. We
can safely just make BUFSIZE the maximum amount of data the schannel_recv()
function can return without it breaking any properly written code!
It would simplify the code without breaking anything...
Then, as a follow-up improvement the code could probably use the 'buf' buffer
immediately instead of separately storing received data in a malloc'ed buffer
that is then memcpy()'ed to 'buf'. It would save one malloc/free of a 16K
buffer, and also skip memcpy()ing all data that is received. (It will be
copied at least once afterwards anyway.)
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2012-06-13