If one implements an array class the way it is commonly implemented, its performance is slower compared to its STL equivalent like a vector. So what makes STL containers/algorithms fast?
If one implements an array class the way it is commonly implemented, its performance
Share
STL algorithms like
for_eachtake function objects that can be easily inlined. C, on the other hand, uses function pointers which are much more difficult for the compiler to optimize.This makes a big difference in some algorithms like sorting in which the comparer function must be called many times.
Wikipedia has some more information in case you are interested.
EDIT:
As for the STL’s vector class, I don’t think it’s necessarily faster that what you could find in, say, glibc.