The first one of those is ok - as long as you remember to free databuffer later. The second is wrong, the argument to getBytes:range: has to be an allocated buffer of size at least the length of the range you pass in. That second one is just copying data to a random place in memory, probably zero.
On 26 May, 2014, at 9:44 pm, Pax <[email protected]> wrote: > Apologies - the obvious important detail, and I missed it out entirely. I > have tried both of the following with the same result: > > unsigned char* databuffer = (unsigned char*)malloc(datasize); > [datastream getBytes:&databuffer range:NSMakeRange(positionCounter, > datasize)]; // Packet content > > and > > unsigned char* bytes; > [datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; > // Packet content > > Either way, I get the same result. > > > > On 26 May 2014, at 14:16, Uli Kusterer <[email protected]> wrote: > >> On 26 May 2014, at 06:02, Pax <[email protected]> wrote: >>> This is my snippet of code: >>> [datastream getBytes:&bytes >>> range:NSMakeRange(positionCounter, datasize)]; // Length of packet content >>> positionCounter+= datasize; >> >> What is bytes declared as, and what do you initialize it to? >> >> Cheers, >> -- Uli Kusterer >> “The Witnesses of TeachText are everywhere...” >> http://zathras.de >> > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org > > This email sent to [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
