Heya, the malloc(1) isn't being stingy. As the comments say, it will be resized with realloc calls later on.
Basically, it allocates a single byte so there's a valid memory address in chunk.memory so that realloc can be called on it later on. If it started out NULL, there would have to be an if check before the realloc call, so it just simplifies things a little. as far as the chunk.size, that is saying how much data there is. It should be set to 0 starting out because when data comes in, it will get changed to something else later on. If you set it to 10000 starting out, the code will think there is 10k of data that isn't really there which im sure is causing your problems. Hope this helps! On Sun, Feb 27, 2011 at 8:37 PM, <[email protected]> wrote: > Hi everyone. I'm still a newb trying to learn C99 and use libcurl. > > I have successfully modified this code: > > http://curl.haxx.se/libcurl/c/getinmemory.html > > It works perfectly. However, where it says chunk.memory = malloc (1) , I > decided to be less stingy and give it malloc (10000). Now, I modify the > next line to chunk.size = 10000 ; and suddenly my code produces errors. > > Am I misunderstanding the purpose of MemoryStruct.size ? > > Richard > > > > > ------------------------------------------------------------------- > List admin: http://cool.haxx.se/list/listinfo/curl-library > Etiquette: http://curl.haxx.se/mail/etiquette.html > ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
