[Qgis-developer] STL vs. Qt containers

Mateusz Loskot mateusz at loskot.net
Sun Oct 29 09:07:54 EST 2006


Martin,

Martin Dobias wrote:
>> First, in this particular example following should be preferred for
>>  best performance and optimization:
>> 
>> std::list<int>::const_iterator end = lst.end(); for 
>> (std::list<int>::const_iterator it = lst.begin(); it != end; ++it)
> 
> Well, lst.end() is a constant operation, isn't it?

It's not guaranteed by the Standard.

> Honestly, what time savings can we get with the optimization shown 
> above for e.g. one milion items? 1 milisecond - or more?

Very significant.
it++ makes a temp copy and next increment.
++it does not make any copy.
This is a principle of STL usage.

> With time and some programming experience I tend to use these rules:
>  1. Don't optimize 2. If it's slow, profile it and optimize it at 
> high-level
> 
>> Finally, what's simpler and less error prone comparing to this?
>> 
>> std::copy(lst.begin(), lst.end(), 
>> std::ostream_iterator<int>(std::cout, "\n"));
> 
> Sorry but for me this is nearly unreadable without an explanation 
> what does it do. I know that's just my ignorance of learning the C++
>  library, but consider that great amount of people don't know from it
>  much more than just basic usage of iostreams, strings, lists and 
> vectors.

Martin, I even have no idea how to address it :-)
The only answer I can form is that if you don't want to learn C++,
why do you use it. It's like "People might not know what Red light on a
crossing does mean." or "Please, don't use pointers because not everyone
knows what dereferencing operator means."

As you know, I'm not a very active developer of QGIS, so I just
wanted to present facts into discussion which I believe are worth to
consider, and to belie wrong statements, but I'd not want to discuss if
people should know feature X of programming language they use or not.

Please, let me finish this thread on my side.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Qgis-developer mailing list