cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Prevent copying of data between curl buffer and user provided buffer

From: Michael Mastroianni <MMastroianni_at_choicestream.com>
Date: Tue, 11 Oct 2005 10:16:42 -0400

Why not use the string directly in the callback, something like this

size_t WriteMemoryCallbackStdString(void *ptr, size_t size, size_t
nmemb, void *data)
{
    register int realsize = size * nmemb;
    string & contents = *(string *)(data);
    contents.append((char *)ptr,realsize);
    return realsize;
}

-----Original Message-----
From: curl-library-bounces_at_cool.haxx.se
[mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of Bharath
Devanathan
Sent: Monday, October 10, 2005 9:06 PM
To: curl-library_at_cool.haxx.se
Subject: Prevent copying of data between curl buffer and user provided
buffer

Hello,

When using libcurl to fetch a webpage, I provide it with a
write_function
with the signature
"size_t function( void *ptr, size_t size, size_t nmemb, void *stream)"

The webpage is now stored in a buffer pointed to by ptr. To make it
really
useful, I end up having to copy the string from the ptr buffer to
another
buffer( in this case a std::string).

Is there a way I can avoid making this copy? Ideally I would like to
pass a
buffer to libcurl, so that it stores the webpage directly in that
buffer.

Thanks in advance,
bharath
Received on 2005-10-11