cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Is it possible to avoid memcpy when doing http PUT from memory buffer

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 15 Jan 2016 14:16:44 +0100

On Fri, Jan 15, 2016 at 12:39:44PM +0000, JOHAN LANTZ wrote:
> When doing a PUT, then in the read_callback I copy the data into the buffer
> provided by curl like this:
>
> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
> {
>
> tu_http_transaction *transaction = (http_transaction*)userp;
>
> int bytes_read = 0;
>
> if (size*nmemb > transaction->size_left) {
>
> bytes_read = transaction->size_left;
>
> memcpy(ptr, transaction->data + (transaction->size - transaction->size_left),
> bytes_read);
>
> transaction->size_left = 0;
>
> } else {…}
>
>
> Out of curiosity, if I know my buffer is valid until the transfer finishes, is
> there a way to avoid this memcpy and just tell curl the address of the data to
> be PUT?

There was a proposal for a zero-copy interface to libcurl, but it deemed not
worthwhile implementing.
https://github.com/bagder/curl-www/blob/aad7665f5737d11bed2b3b382d4c592d1a5ba692/dev/no_copy_callbacks.txt

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2016-01-15