Subj : Re: BC5.02 STL question To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Mon May 31 2004 03:28 pm When used only to increment, no use of the value: ++i increment and use the value i++ load the value, save a copy, increment the value, use the original value Post increment can call a copy constructor and may have other side effects depending upon the details of the object involved. For an integer where the value is not used in the statement the overhead is small but still bad compared to pre-increment. That is probably why the compiler writers decided to make the optimizer detect the situation and generate code for pre-increment. > Also, it seems that iterator vs. index has more to > do with coding style when using a vector. I guess > an iterator is really more advantageous when using > a container other than vector. Assuming that all that is being done only involves the vector itself so no side effects came into play then yes, the overhead of iterator vs index is small. However that small overhead can add up to a large number of CPU cycles if operations are done on large vectors or many iterative or looping operations done on vectors. for_each uses iterators and is usually a bit more efficient. .. Ed > MarvinAvery wrote in message > news:40bb5863$1@newsgroups.borland.com... > Thanks for the info. > > I didn't know about ++i vs. i++. I thought they were equally .. efficient. > > Also, it seems that iterator vs. index has more to do with > coding style when using a vector. I guess an iterator is > really more advantageous when using a container other > than vector. .