views:

565

answers:

1

I've run into this problem a couple times now. Last time, I wanted to create an array of arrays (matrix) of BOOL's. I ended up encapsulating them in NSStrings, because apparently NSArray only has arrays of objects.

This time, want an array of arrays again, but of CGPoints. I'm going to be using these to draw images to the screen. Is there a way to create an array of CGPoints without them being objects? Should I even worry about the memory/performance overhead of having a matrix of 96 objects?

+2  A: 

I would guess that 96 is a pretty small number, and you needn't worry about it too much. If you're using CGPoints, you can use NSValue to wrap the points (rather than NSStrings), by using its [NSValue valueWithCGPoint:] method on the iPhone or [NSValue valueWithPoint:] on Mac OS X 10.5.

That being said, it's quite easy to create an array of CGPoints if you know the number of them ahead of time. I talked about these options (for strings, not points) here. In this case, you can just make a 2D Array in C like this:

CGPoint myArray[32][3];

And then use it like CGPoint onePoint = myArray[2][1];

Jesse Rusak