• 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: Nick Zitzmann <email@hidden>
  • Date: Fri, 20 Mar 2009 12:44:54 -0600


On Mar 20, 2009, at 12:33 PM, James Maxwell wrote:

But this seems like a memory hungry way of doing things (even though setFloatData is a "properly written" accessor, I think, and does release the current copy "m_floatData" before storing the new one). Is there any way to just operate on the float array "in place", so to speak?

Yes; just pass the float array(s) around as arguments. Using NSData to encapsulate C arrays is kind of awkward, unless you requested the memory using malloc() and use +dataWithBytesNoCopy: to add the bytes to the autorelease pool/garbage collector.


Of course, if you need to add the array(s) to a collection object of some sort, then you should use NSValue, not NSData.

Just in case there's a problem with the accessor, I'm doing something like this:

- (void) setFloatData:(NSData *) theData
{
   if(m_floatData)
       [m_floatData release];
   m_floatData = [theData retain];
}


Bad idea. If m_floatData == theData, then your code will probably crash. Also, calling -release on a nil pointer is OK, since nothing will happen if you send a message to a nil pointer. What you should do instead is this: (typed in Mail)

- (void)setFloatData:(NSData *)theData
{
	if (m_floatData != theData)
	{
		[m_floatData release];
		m_floatData = [theData retain];
	}
}

Nick Zitzmann
<http://www.chronosnet.com/>



_______________________________________________

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>
References: 
 >NSData confusion (From: James Maxwell <email@hidden>)

  • Prev by Date: Re: NSTimer & Runloop questions
  • Next by Date: Re: need advice on subclassing NSScrollVIew
  • Previous by thread: NSData confusion
  • Next by thread: Re: NSData confusion
  • Index(es):
    • Date
    • Thread