Re: A simple doubt about array
Re: A simple doubt about array
- Subject: Re: A simple doubt about array
- From: Jens Alfke <email@hidden>
- Date: Tue, 10 Jun 2008 18:09:32 -0700
It would be a lot more efficient to implement a two-dimensional m-by-n
array as a single NSArray with m*n elements. Then the object at
(row,column) is the object at index row*width+column. That's basically
how C implements multi-dimensional arrays.
You can't make this accessor a simple category method on NSArray,
because it needs to know the width (and categories can't add instance
variables.) But it would be very easy to make your own class that had
an NSArray and the width as instance variables.
And you might just want to implement this as a C array, if the height
and width are hard-coded. You just have to remember to retain objects
you store into the array and release them when they're removed or
replaced. That way you won't run into the issue that NSArray objects
can't contain empty (nil) elements...
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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