Re: multidimensional arrays
Re: multidimensional arrays
- Subject: Re: multidimensional arrays
- From: Thomas Davie <email@hidden>
- Date: Tue, 15 Mar 2005 12:02:49 +0000
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?
Then you just have to ask whether your array is small enough to fit in
cache (or used in small enough parts to fit in cache), because two
cache hits is gonna be a lot faster than one cache hit, and a multiply.
This is the level at which optimization gains you nothing but
obfuscated code - you probably gain 0.001 seconds on one chip and loose
the same on a different chip... So stop trying to find that one clock
cycle difference it makes and start trying to (a) write code that looks
nice, and (b) write fast algorithms.
Bob
_______________________________________________
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