Re: NSData confusion
Re: NSData confusion
- Subject: Re: NSData confusion
- From: Boyd Collier <email@hidden>
- Date: Fri, 20 Mar 2009 14:57:06 -0700
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