Re: Unarchiving issues
Re: Unarchiving issues
- Subject: Re: Unarchiving issues
- From: glenn andreas <email@hidden>
- Date: Mon, 02 Aug 2010 12:56:52 -0500
On Aug 2, 2010, at 12:46 PM, James Maxwell wrote:
> // set the contents of the array
> continuations = (float*)[aDecoder decodeBytesForKey:@"continuations" returnedLength:&size];
>From the header file:
- (const uint8_t *)decodeBytesForKey:(NSString *)key returnedLength:(NSUInteger *)lengthp; // returned bytes immutable, and they go away with the unarchiver, not the containing autorlease pool
And from the documentation:
Discussion
The returned value is a pointer to a temporary buffer owned by the receiver. The buffer goes away with the unarchiver, not the containing autorelease pool. You must copy the bytes into your own buffer if you need the data to persist beyond the life of the receiver.
So if your setContinuationSize: allocates memory, you should:
const uint8_t *bytes = [aDecoder decodeBytesForKey:@"continuations" returnedLength:&size];
NSAssert(size == [self continuationsSize] * sizeof(float), @"Bad size of bytes returned from decoding");
memcpy(continuations, bytes, size);
Glenn Andreas email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden