• 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: A simple doubt about array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: A simple doubt about array
      • From: Matt Gough <email@hidden>
    • Re: A simple doubt about array
      • From: Keith Duncan <email@hidden>
References: 
 >Re: A simple doubt about array (From: Adam Leonard <email@hidden>)

  • Prev by Date: Re: Spotlight sources w/o actual files?
  • Next by Date: Re: Where are window prefs stored?
  • Previous by thread: Re: A simple doubt about array
  • Next by thread: Re: A simple doubt about array
  • Index(es):
    • Date
    • Thread