cURL / Mailing Lists / curl-users / Single Mail


Re: cURL easy interface / buffer alloc.

From: Daniel Stenberg <>
Date: Wed, 25 Jan 2006 00:14:03 +0100 (CET)

On Tue, 24 Jan 2006, Robbie wrote:

> I'm using libcurl easy interface to accomplish two tasks.

Then consider the curl-library list, which is for libcurl users, hackers and

> 1. to grab data from a url at will, and process it, and
> 2. initiate a stream and grab an updated sequence of data and process it.
> In the first case, I notice my data chunks in memory are the same. That is,
> its not being updated. When I call curl_perform, does it actually get new
> data and put it in the specified buffer or do I have to update it myself?

You're talking about the buffer passed to the write callback here? Then yes,
it is filled with contents before the function is called and you need to copy
the data or do what you want with it as when you return from the write
callback the data will be gone.

> Or am I actually using the right functions? I tried clearing the buffer
> after processing but I got segfaults as if its looking for the same data.
> Does anyone have any ideas here? My App uses libcurl much like the
> getinmemory.c example and I've written a thread form that does the same
> thing.

... and in that example you see how the data is copied from the buffer every
time the callback is invoked.

> For the second case, I just have one question, How does libcurl determine
> the size of the buffer to use in such a case?

It has a fixed-size internal buffer that it fills with a varying amount of
data depending on the situation and then it calls the callback telling it how
much of the buffer that is filled with data for the callback to use.

I believe all this (and more) is mentioned in the libcurl tutorial.

  Commercial curl and libcurl Technical Support:
Received on 2006-01-25