Possible Duplicate:
When do you prefer using std::list<T> instead of std::vector<T>?
I just watched the recording of the GoingNative'12 talk by Bjarne Stroustrup. And I'm a bit confused.
In this talk he in particular discusses the vector
vs list
question and suggest that in many cases vector
is faster even if you insert and remove intensively to/from the middle, as compilers can optimize a lot of things and like compact structures. And the conclusion(as I understand it) is: first use vector
and later think whether you need something else. That sounds reasonable, but taking into account the first observation, what criteria I should take into account? I always thought that if you insert/remove intensively - use list. Similar things are suggested in some topics here. See
Relative performance of std::vector vs. std::list vs. std::slist?
and
vector vs. list in STL
And now according to Stroustrup I was wrong.
Of course I can write a couple of tests and try to figure out what to use in each particular situation, but is there a theoretical way?