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
Post a Comment