cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: malloc/free.. callback functions

From: codemastr <codemstr_at_ptd.net>
Date: Sat, 3 Apr 2004 12:04:45 -0500

> Can we add CURLOPT or a function for applications to register their own
> malloc/free/realloc/strdup callback functions. If these callback
> functions are not set, then CURL can fallback to the system calls. I
> know this is major change, but should be trivial. I can provide the
> patch if you are interested.
I agree it would be easy, but why is it necessary? The way I see it, at best
this requires an extra if() every time memory is allocated/freed. That might
not sound like a lot, but it could easily add up. And, to make the
transition easy, it would probably require an extra if() and an extra
function call. I mean this because things like char *buf = malloc(len) would
not work since you need an if() in there. That seems like a lot of cost to
incur unless there is a really good reason why you'd need this.

The only reason I could see for doing this is for debugging, and curl
already supports overriding it for debugging purposes. However, it overrides
it at compiletime to minimize the cost.

I just don't see the need to add 5 new CURLOPTs for this (you need 5 because
you left out calloc) as it just doesn't seem necessary to me, and even if it
is, it doesn't seem like the most efficient way to implement it.

Dominick Meglio.
Received on 2004-04-03