• 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: NSData confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData confusion


  • Subject: Re: NSData confusion
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 20 Mar 2009 11:55:21 -0700

On Mar 20, 2009, at 11:33, James Maxwell wrote:

I've been using NSData to wrap up float arrays and matrices, so I can pass them around my methods and classes.
However, I'm finding they're using loads of memory. Now, I do admit this is probably because I'm not doing this properly, so I'd like some clarification. The NSData objects are instance variables, and I need to be able to perform operations on the float arrays/matrices inside, and have these operations permanently change the state of the array/matrix.


I've been doing something like:

- (NSData *) doSomethingToFloatData
{
   float stuff[20];

   [[self floatData] getBytes:stuff];

   // do something to change the float values in stuff

[self setFloatData:[NSData dataWithBytes:stuff length:(20 * sizeof(float))]];

   return [self floatData];
}

Seems to me you probably want to be using NSMutableData:

- (void) doSomethingToFloatData
{
	float* stuff = [m_floatData mutableBytes];
	// do something to change the float values in stuff
}

All you need to do is create the NSMutableData object with a suitable size to begin with (it'll get zero-filled), and to resize it if the number of floats it contains ever changes.


_______________________________________________

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


  • Follow-Ups:
    • Re: NSData confusion
      • From: James Maxwell <email@hidden>
    • Re: NSData confusion
      • From: James Maxwell <email@hidden>
References: 
 >NSData confusion (From: James Maxwell <email@hidden>)

  • Prev by Date: Re: [noob] Best practice for creating multiple instances of a View
  • Next by Date: Re: NSData confusion
  • Previous by thread: Re: NSData confusion
  • Next by thread: Re: NSData confusion
  • Index(es):
    • Date
    • Thread