• 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: multidimensional arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multidimensional arrays


  • Subject: Re: multidimensional arrays
  • From: Pandaa <email@hidden>
  • Date: Tue, 15 Mar 2005 12:54:07 +0100


2005-03-14 kl. 20.56 skrev Serge Meynard:

You do realize that C fully supports multi-dimensional arrays, you can do myArray[x][y] in plain C (and Objective-C is super set of C).

Only if your array size is fixed at compile-time. I'm talking about arrays whose size is only known at execution time, and are allocated dynamically.

If you want it on the stack, C99 supports variable sized arrays. If not, just malloc.


But for heap allocated memory, there's no way to get [][] syntax without ** references and you'll want avoid that as it will cost two memory access to access a single array element ( not counting operator overloading, which might not compile down do a direct memory access ). Especially if you'll be using this in loops, where the compiler may not be able to move a constant row indexing out of the loop ( if you array wasn't declared doubly restricted, e.g. ).

Since your access is going to be array+x*ysize+y or array+y*xsize+x anyway, does it really matter what syntax you use?

The reason there is no multi dimensional NSArray class is probably that you seldom need multi dimensional arrays of Cocoa objects. Typically you need multi dimensional arrays in the lower levels of your program, and there wrapping a multidimensional array in ObjC imposes a lot of unnecessary overhead and makes it hard to pass your data to C and C++ functions without breaking encapsulation.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. email@hidden . . www.synapticpulse.net .


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: multidimensional arrays
      • From: Thomas Davie <email@hidden>
References: 
 >multidimensional arrays (From: Daniel Child <email@hidden>)
 >Re: multidimensional arrays (From: Serge Meynard <email@hidden>)
 >Re: multidimensional arrays (From: Shawn Erickson <email@hidden>)
 >Re: multidimensional arrays (From: Serge Meynard <email@hidden>)

  • Prev by Date: Re: dataUsingEncoding: vs. archivedDataWithRootObject:
  • Next by Date: Re: multidimensional arrays
  • Previous by thread: Re: multidimensional arrays
  • Next by thread: Re: multidimensional arrays
  • Index(es):
    • Date
    • Thread