Programming Tips - How can I make my STL list faster?

Date: 2008oct1
Language: C/C++
Keywords: STL, Standard Template Library, optimize, speed

Q.  How can I make my STL <list> faster?

A.  <list> is doubly-linked which isn't needed in many applications.
Consider using <slist> which is singly-linked.  Takes less time linking
and it also uses less space.

Try using a <vector> instead.  You might be surprised.  Its sometimes
faster since it doesn't have do a malloc() for each element.

Can you reserve() some space?  This often helps.