[Effective-cpp] Item 1: Uses and Abuses of vector

White Wolf wolof at freemail.hu
Wed Oct 27 11:23:00 EDT 2004


effective-cpp-bounces at accu.org wrote:
[SNIP]
> Maybe you missed this from my reply to a different part of the thread:
> 
> <quote>
> I must confess, I took Herb at his word on this when I
> brought it up for summary, but the discussion caused me to
> examine the question more.
> 
> It made me curious about what the performance might be, so I
> wrote a couple of little programs to build up a really long
> vector of a million ints, then loop through it and print out
> the values (dumping the output to /dev/null) and timed it.
> There was no appreciable difference between the two variants
> -- indeed what I had thought would be the more efficient loop
> was slightly slower.  The platform was linux, the compiler
> g++ 3.2.3.  So my guess would be that this compiler does not
> recalculate the value of the end iterator each time.

I have missed that one somehow.  ACCU lists work weird for me (some mails
are delayed hours) but it is equally possible that I have just missed it.

> On another point raised, I would "not" use this sort of loop
> for a vector that I intend to modify, especially if the
> modification involved removing items.  I learned this the
> difficult way, once trying to iterate through a vector to
> remove elements, and at times, the removal would blow the "end
> iterator" away. </quote>
> 
> (in my original post i accidentally left out the "not")

I have seen that one, but I have seen it long after I have sent my mail.
Somehow my mail arrived much later, after yours.  But I swear I have sent it
way before I saw your two mail (the one with the  missing not and the one
with the correction).

Thanks for the answer!  I was really worried that I have missed something
important.

Attila





More information about the Effective-cpp mailing list