• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problem encoding large float* matrix
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem encoding large float* matrix


  • Subject: Re: problem encoding large float* matrix
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 1 Dec 2009 11:27:07 -0800

On Dec 1, 2009, at 10:47, James Maxwell 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);
> NSData* coincData = [NSData dataWithBytesNoCopy:&coincidences length:coincsSize];
> [aCoder encodeBytes:[coincData bytes] length:coincsSize forKey:@"coincidences"];
>
> The app runs fine, but when I try to save, boom... EXC_BAD_ACCESS.
>
> Is this a decent way to save a float* array?

Not really. :)

You don't show the declaration of 'coincidences', but if that's a pointer to a malloc'ed array, then '&coincidences' isn't where you want to copy the data from. That's likely why you're getting a big boom. I think you meant:

> NSData* coincData = [NSData dataWithBytesNoCopy:coincidences length:coincsSize];

Nick already pointed out that 'dataWithBytesNoCopy:length:' probably isn't the correct method to use here, and (even if it was) putting the data "into" a NSData object, then immediately encoding it with 'encodeBytes:length:forKey:' is unnecessary. What's wrong with just:

> [aCoder encodeBytes:coincidences length:coincsSize forKey:@"coincidences"];

? (But remember this is architecture-specific as regards to endianness.)


_______________________________________________

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

References: 
 >problem encoding large float* matrix (From: James Maxwell <email@hidden>)

  • Prev by Date: Re: NSString out of scope
  • Next by Date: Re: problem encoding large float* matrix
  • Previous by thread: Re: problem encoding large float* matrix
  • Next by thread: Re: problem encoding large float* matrix
  • Index(es):
    • Date
    • Thread