kage wrote:
an optimizing compiler might inline a function like getNext(), in which case, no, it wouldn't decrease performance. however, if it's not inlined, then you're looking at a lot of stack manipulation that is always implicit with any compiled-in function call, and since linked lists are used by programmers in almost all cases for their performance benefits, it seems shameful for a programmer to put it within a function, even if they knew it was going to get inlined when they compiled it. in general, using functions for that kind of linked-list manipulation is a signature computer-science type thing to do, where the student explored linked lists as an "interesting data structure" rather than the practical applications behind it.
Well in case of the C++ STL linked list algorithm you get inlining whether you want it or not. Simply because the entire STL (std::list in ) implementation is templated, so the overhead you get from that really is only compile time overhead. Plus comparing an std::vector to a linked list is rather inaccurate (vector had indexed access just like an array, which increases its overhead because memory will have to be maintained sequentially (i.e. a vector
must make sure that all contained objects follow up on eachother in memory: std::vector a; (++&a[0]) == (&[1])).
Anyway most STL algorithms really only provide type safety and encapsulation above the C implementations. And because they're all template instantiations they will not imply any performance degradation (not with a good compiler that is, g++ is a good in in this respect).