Re: multidimensional arrays
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