• 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: mm w <email@hidden>
  • Date: Fri, 20 Mar 2009 15:58:46 -0700

on the backside,  for this kind of game, sometimes is good to know to
use C rather than
object/scalar layers, and use only an object to represent the final result.

Cheers!

On Fri, Mar 20, 2009 at 2:57 PM, Boyd Collier
<email@hidden> wrote:
> In a program I've been developing, I make a lot of use of matrices of
> doubles, and I've written some straight-forward code for doing this that
> might be of interest to you.  If you're interested, I'd be happy to send it
> to you.
>
> Boyd
>
>
>
> On Mar 20, 2009, at 11:33 AM, 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];
>> }
>>
>> 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? Do I really need
>> the "[self setFloatData]" call, if I want the changes to stuff to be
>> retained?
>>
>> 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];
>> }
>>
>> This is how I've seen it done in the Apple docs, but maybe this isn't the
>> best way to do things...(??)
>>
>> Keep in mind, I'm from a Java background, so I may be missing some things
>> that would be obvious to a C expert... I'm also open to a totally different
>> way of doing all this, with the one caveat that the float arrays and
>> matrices can get fairly large, and I'm running through lots of them (i.e.,
>> NSMutableArrays will likely be too slow and awkward). Would NSValue be more
>> convenient?
>>
>> J.
>> _______________________________________________
>>
>> 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
>>
>
> _______________________________________________
>
> 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
>



--
-mmw
_______________________________________________

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

  • Prev by Date: Re: Is there an iPhone mailing list?
  • Next by Date: Re: Customization of NSSavePanel
  • Previous by thread: Re: NSData confusion
  • Next by thread: q's regarding appropriate use of core data?
  • Index(es):
    • Date
    • Thread