Re: performance of encoding an array of structs
Re: performance of encoding an array of structs
- Subject: Re: performance of encoding an array of structs
- From: Dorian J <email@hidden>
- Date: Tue, 12 Jun 2007 13:14:27 -0500
Basically, when you encode an NSArray, it puts it into a plist. Since
you're using a c array, use an +[NSData dataWithBytesNoCopy:length:
] using _buffer and sizeof(MVTimedPoint) * _bufferSize as length and
store the resulting NSData. Then you can load the NSData straight
into your buffer when decoding. No converting to strings or plists,
just raw data. That should be a few orders of magnitude quicker.
Dorian
On Jun 12, 2007, at 12:11 PM, Hank Heijink wrote:
The encoding function is this one:
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:[self contents] forKey:@"contents"];
[coder encodeInt:_bufferSize forKey:@"bufferSize"];
}
- (NSArray *)contents
{
NSMutableArray *result = [[NSMutableArray alloc]
initWithCapacity:_bufferPointer];
int i;
// Not very efficient, but couldn't think of an easier way. I
tried converting the MVTimedPoints to NSStrings
// in a C array and then converting that array with +[NSArray
arrayWithObjects:count:], but that doesn't seem
// to be a whole lot faster.
for (i = 0; i < _bufferPointer; i++)
[result addObject:MVStringFromTimedPoint(_buffer[i])];
}
I ran Shark on my application and it seems to spend all its time in
-[NSKeyedArchiver finishEncoding], specifically in _flattenPlist in
CoreFoundation. This doesn't mean all that much to me, and I can't
figure out which of my functions make it so slow.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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