Re: NSData encode decode
Re: NSData encode decode
- Subject: Re: NSData encode decode
- From: James Maxwell <email@hidden>
- Date: Thu, 2 Apr 2009 15:58:59 -0700
Just a quick update... If I do this:
const float *markovBytes = (float *)[coder
decodeBytesForKey:@"normalizedMarkovGraph" returnedLength:&mGraphSize];
[self setNormalizedMarkovGraph:[NSData dataWithBytes:markovBytes
length:mGraphSize]];
it seems to work (it doesn't raise an exception). Don't know if the
data's actually in place, mind you!
thanks, and sorry for the false alarm.
(Mind you, if anybody sees something clearly wrong, please let me know!)
J.
On 2-Apr-09, at 3:40 PM, James Maxwell wrote:
I'm having some real trouble with encoding/decoding a 2D float
matrix wrapped in an NSData.
I'm doing this:
- (void) encodeWithCoder:(NSCoder*) coder
{
NSUInteger mGraphSize = [[[[self containerNode] spatialPooler]
quantizationCentres] count] * [[[[self containerNode] spatialPooler]
quantizationCentres] count] * sizeof(float);
[coder encodeObject:[self containerNode] forKey:@"containerNode"];
[coder encodeObject:[self chains] forKey:@"chains"];
[coder encodeInt:[self maxGroups] forKey:@"maxGroups"];
[coder encodeInt:[self transitionMemorySize]
forKey:@"transitionMemorySize"];
[coder encodeInt:[self maxChainLength] forKey:@"maxChainLength"];
[coder encodeInt:[self runMode] forKey:@"runMode"];
[coder encodeBytes:[[self normalizedMarkovGraph] bytes]
length:mGraphSize forKey:@"normalizedMarkovGraph"];
}
- (id) initWithCoder:(NSCoder*) coder
{
NSUInteger mGraphSize;
[self setDefaults];
[self setContainerNode:[coder decodeObjectForKey:@"containerNode"]];
[self setChains:[coder decodeObjectForKey:@"chains"]];
[self setMaxGroups:[coder decodeIntForKey:@"maxGroups"]];
[self setTransitionMemorySize:[coder
decodeIntForKey:@"transitionMemorySize"]];
[self setMaxChainLength:[coder decodeIntForKey:@"maxChainLength"]];
[self setRunMode:[coder decodeIntForKey:@"runMode"]];
[self setNormalizedMarkovGraph:[NSData dataWithBytes:[coder
decodeBytesForKey:@"normalizedMarkovGraph"
returnedLength:&mGraphSize] length:mGraphSize]];
[self calculateMarkovChainModulus];
return self;
}
It appears to save correctly, though it's pretty much impossible to
know until I re-load the data... But no crashes on saving. When I
open it, I gdb pops up at the [self setNormalizedMarkovGraph...]
line with this:
#0 0x9694ee17 in objc_exception_throw
#1 0x9374eeeb in +[NSException raise:format:arguments:]
Probably that error doesn't say anything, but I'm confused anyway.
Any help appreciated.
cheers,
J.
_______________________________________________
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
_______________________________________________
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