Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Interesting advantage of using indices instead of iterators
Interesting advantage of using indices instead of iterators [message #7615] Wed, 10 January 2007 11:52 Go to next message
mirek is currently offline  mirek
Messages: 13976
Registered: November 2005
Ultimate Member
From alt.comp.lang.c++.moderated:

Jeff Koftinoff wrote:

> My only issue with STL's iterator design is that the pointer-style
> based algorithms make it a lot tougher for the compiler to optimize the
> resulting code, taking advantage of cpu pipelining and parallel
> execution units - especially without having the 'restrict' keyword to
> tell the compiler that the dereferenced iterators are not aliasing
> other variables used within the loop. ie, with array indexing the
> compiler can easily tell that certain lines of code can be
> parallelized, but changing a pointer in the loop makes it very hard on
> the compiler designers to track what optimizations can happen. In my
> code on one platform, I've found I could optimize the loop time from
> 170 clock cycles per iteration down to 10 just by using array indexing
> instead of pointer increments! (TMSC6701 DSP, VLIW)

I had many reasons to avoid iterators, but this one is new to me )

--
Mirek Fidler
U++ team leader. http://www.ultimatepp.org
Re: Interesting advantage of using indices instead of iterators [message #7616 is a reply to message #7615] Wed, 10 January 2007 12:24 Go to previous messageGo to next message
Balage is currently offline  Balage
Messages: 17
Registered: December 2006
Promising Member
I've also read a lot about this. It's not just iterators.

Many newcomers (including myself at that time) try to use pointer arithmetic to save that addition on array indexing inside loops. But they all fail to realize, that the compiler can do way much better optimizations if it knows what is just read from memory, and what is updated (and also when). Pointer arithmetic makes it a lot harder to figure that out, as the compiler cannot easily track where a pointer currently points to.
With regular array indexing, it exactly knows what element, when, and how is being accessed, and that's very good for optimization.

[Updated on: Wed, 10 January 2007 12:30]

Report message to a moderator

Re: Interesting advantage of using indices instead of iterators [message #7617 is a reply to message #7615] Wed, 10 January 2007 12:47 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Perhaps there are more important reasons (like that one you mentioned) but I don't like iterators because of long declarations...
map<string, const Point&>::const_iterator
vector<int>::iterator

God, what's that? Wink
That's one of reasons why auto is comming up. Indexes are much more natural IMO.
Previous Topic: OSes: request for "advertising" audit
Next Topic: Funny way how to get thread specific id
Goto Forum:
  


Current Time: Fri May 10 05:07:25 CEST 2024

Total time taken to generate the page: 0.02360 seconds