3.1. BUFFER_SIZE integer

[<<<] [>>>]

curl::option CurlHandle,"BUFFER_SIZE",1024

When a file is downloaded but not stored in a file the function curl::perform(CURL) returns the content of the downloaded file as a huge string. During the download this string is stored ina temporary buffer. The size of this buffer increases gradually as more and more bytes come. If there are 10 bytes coming at a time then the buffer will grow only ten bytes. This also means a new buffer allocation and copying the content of the buffer, which consumes system resources, especially for large files.

If you happen to know the estimated size of the file, you can set the initial size of the buffer to a huge value using this option. For example if you know that the file is 1024 bytes, you can set this option as in the example above. In that case when the first byte comes from the URL the 1024 byte length buffer is increased and when the consecutive bytes come there is space to store them without reallocating the buffer.

You need not worry about using this buffer when you handle small files, like web pages. If you see performace or memory shortage problems, then you may consider this option along with the option FILE that helps you store the downloaded file on disk.


[<<<] [>>>]