Re: NSData confusion
Re: NSData confusion
- Subject: Re: NSData confusion
- From: James Maxwell <email@hidden>
- Date: Fri, 20 Mar 2009 12:28:23 -0700
okay, but what about matrices?
I've set them up using:
float **theMatrix = [[self matrixData] mutableBytes];
and this part seems okay - or at least, it compiles... But how do I
then access the matrix.
I've been using normal C-style array notation, thus far:
theMatrix[i][j] = 0.6666;
but this gives me an EXC_BAD_ACESS error when I run it.
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