On Tue, Dec 1, 2009 at 1:47 PM, James Maxwell <jbmaxw...@rubato-music.com> wrote: > I'm trying to save the state of my app. It chews up a lot of memory, most of > which is in large float* matrices. I'm getting an EXC_BAD_ACCESS error in > -encodeBytes:length:forKey: and I'm just wondering what might be happening. > The float* "coincidences" is a malloced array. > > NSUInteger coincsSize = maxCoincs * inputSize * sizeof(float);
This looks suspicious to me. Based on the variable names, it looks like you malloc(maxCoincs * sizeof(float)), then store the actual number of floats in the buffer in inputSize. If that's what you're doing, you only need to multiply by maxCoincs (to get the size of the whole buffer) or by inputSize (to find out how much of the buffer is actually in use) - not by both of them. > NSData* coincData = [NSData dataWithBytesNoCopy:&coincidences > length:coincsSize]; > [aCoder encodeBytes:[coincData bytes] length:coincsSize > forKey:@"coincidences"]; As someone else said, if you created the buffer with "coincidences = malloc(...)", then you don't need to dereference it here; doing so will give you the address of the pointer variable, not the address of the buffer to which it points. What's the point of creating the NSData object here? Wouldn't this be just as good? [aCoder encodeBytes:coincidences length:coincsSize forKey:@"coincidences"]; sherm-- -- Cocoa programming in Perl: http://www.camelbones.org _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com