cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: why "mem->memory[mem->size] = 0;" in example getinmemory.c ?

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 19 Jun 2011 16:19:30 +0200 (CEST)

On Sat, 18 Jun 2011, Richard Cavell wrote:

> These are commonly asked questions.  I mean no disrespect to the poster.
> Maybe there ought to be more documentation in the source code?

We accept patches to the example source codes as well, so if someone feels he
or she has good ideas on how to improve them...!

If you ask me, I don't think we can make it much simpler. The issues people
still have with it will remain more or less however we change it, as they who
have these problems are beginners and inexperienced persons.

Possibly we could add a bunch of comments to the exist code that explains why
it does what it does.

> What I did in my code was to have a pointer to buffer, and a size_t that
> identified the buffer size.  They are both initialized to zero.  When the
> callback function executes, if there is a pointer, it calls realloc().  If
> there is no valid pointer, it calls malloc().  I've just shifted the
> malloc() into the callback.  No biggie.

This example had something similar to that in the past, but I'm not sure I
think that is a simpler way to do it.

After all, this is an _example_ (meaning that the reader should feel fine to
do it completely different) that shows how you use libcurl. The parts that
aren't about using libcurl I think are less important and should be kept
small.

-- 
  / daniel.haxx.se

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-06-19