Re: multidimensional arrays
Re: multidimensional arrays
- Subject: Re: multidimensional arrays
- From: Pandaa <email@hidden>
- Date: Tue, 15 Mar 2005 18:04:20 +0100
2005-03-15 kl. 13.02 skrev Thomas Davie:
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.
That's not true at all, since there is a true dependency between the
two loads and lwz is a 2:1 instruction and typically, the multiply is
either partially or fully redundant or a multiplication by an induction
variable while the outer lwz can often not be optimized even if it is
fully redundant.
This is the level at which optimization gains you nothing but
obfuscated code
As a general statement, this is simply not true. Wether this "level" of
optimization gains you something, and wether it would lead to
obfuscated code, depends entirely upon the context.
- 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.
I trust everyone to have a sound judgment on when and what to optimize
and when and what not to optimize. Bringing up the "premature
optimization" point everytime someone talks about efficient coding is
redundant at best. Everyone knows their own situation and application
best, so trying to lecture them on what is appropriate for their
situation is simply rude. People are intelligent enough to understand
if a comment were relevant for them or not, don't treat them like
they're not.
Also, if it is never considered OK to discuss what is efficient and
what is inefficient programing - how are we to develop the skills we
need when it *is* important to optimize?
But if you really wanted to bring this up, writing code that looks nice
has very little do to with wether you're writing efficient code or not.
The fastest known algorithm has probably already been selected, or its
design requires deep specialist knowledge of topics very different from
computer programming. Cache-tuning and other optimizations can usually
improve your speed by a rather large integer factor - such as going
from 20 seconds to less than one second to process a large data set.
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. 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