objective c - cocoa code- how to reallocate the buffer in the method which i have used below? -


how reallocate buffer buf, in method have used below?

[filedata getbytes: buf length: 1024]; 

in code have declared buf char n storing 1050 characters in char buf[1050].

you can't "reallocate" buffer on stack, size of defined @ compile time. want use dynamic allocation instead:

#define mybuflen 1024 char *buf = (char *)malloc(mybuflen); [filedata getbytes:buf length:mybuflen]; 

and don't forget free() when you're done it, else leak memory pretty quickly:

free(buf); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -