Re: Iterating a std::vector vs iterating a std::map?
On Nov 24, 7:06 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
"carl" <carl@.com> wrote innews:4b0b34ea$0$280$14726298@news.sunsite.dk:
[...]
Note that using standard containers in performance-critical
code parts is not straightforward and can kill the performance
quite easily if one does not have a clear overview what's
happening behind the scenes. I'm not advocating against using
std::vector, but one has to be aware of the potential problems
and how to work around them. Notably the swap() member
function comes often handy in performance-critical code.
As a general rule, you shouldn't use standard classes, or
classes from any general library, as part of the application
abstractions. You should always define your own classes, with
the exact interface you need (and no more). The standard
classes only appear in the implementation of these classes, so
you can swap them in or out as needed (or even replace them with
a custom implementation, if none of the standard classes meets
your needs).
If the code still seems too slow, then one should use
profiling to see if there are any unexpected bottlenecks. You
cannot rely on profiling only, because if you write uniformly
unefficient code all over the place there will be no
bottlenecks.
Sure there will. The code which is executed most often will be
the bottleneck. You can generally start by not worrying too
much about efficiency; if you've encapsulated correctly, there
will then be no problem improving the efficiency of the places
which really are bottlenecks, i.e. the places which are executed
the most often.
--
James Kanze