Re: NSData confusion
Re: NSData confusion
- Subject: Re: NSData confusion
- From: James Maxwell <email@hidden>
- Date: Fri, 20 Mar 2009 12:09:16 -0700
Oh geez... Of course, NSMutableData... I forgot the m-word.
I'll give that a try, and see how it does.
cheers,
J.
On 20-Mar-09, at 11:55 AM, Quincey Morris wrote:
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
_______________________________________________
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