cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: malloc/free.. callback functions

From: Tor Arntsen <tor_at_spacetec.no>
Date: Sun, 4 Apr 2004 11:19:23 +0200

On Apr 3, 23:51, Seshubabu Pasam wrote:
>CURLOPT was just a suggestion. Typically this is done like this:
>
>typedef void *( *curlMalloc ) ( size_t size );
>typedef void ( *curlFree ) ( size_t size );
>typedef void *( *curlRealloc )( void *mem, size_t size );
>typedef char *( *curlStrdup ) ( const char *str );
>
>curlMalloc curl_malloc = malloc;
>curlFree curl_free = free;
>curlRealloc curl_realloc = realloc;
>curlStrdup curl_strdup = strdup;
>
>void curl_set_memory_callbacks ( curlMalloc m,
> curlFree f,
> curlRealloc r,
> curlStrdup s ) {
> curl_malloc = m;
> curl_free = f;
> curl_realloc = r;
> curl_strdup = s;
>}
[...]

Personally I in general like having "hooks" like this, but in the case
of malloc/free/realloc/strdup I don't think it is necessary. For libc
functions you can always just re-map them the way e.g. ElectricFence does
it, i.e. just write your own malloc/free etc. put them in a library, add link
with it. Your functions will be used instead of the system provided functions.

-Tor
Received on 2004-04-04