• 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 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


  • 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>)
 >Re: multidimensional arrays (From: Pandaa <email@hidden>)
 >Re: multidimensional arrays (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: Weird compiler issue
  • Next by Date: Obj-c and c++ in same file
  • Previous by thread: Re: multidimensional arrays
  • Next by thread: Re: multidimensional arrays
  • Index(es):
    • Date
    • Thread