• 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: 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


  • Follow-Ups:
    • Re: NSData confusion
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >NSData confusion (From: James Maxwell <email@hidden>)
 >Re: NSData confusion (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSData confusion
  • Next by Date: Re: [noob] Best practice for creating multiple instances of a View
  • Previous by thread: Re: NSData confusion
  • Next by thread: Re: NSData confusion
  • Index(es):
    • Date
    • Thread