Why is it so slow iterating over a big std::list?

后端 未结 6 2083
生来不讨喜
生来不讨喜 2020-12-30 18:08

As title suggests, I had problems with a program of mine where I used a std::list as a stack and also to iterate over all elements of the list. The program was taking way to

6条回答
  •  伪装坚强ぢ
    2020-12-30 18:50

    It is due to the large amounts of cache misses you get when using a list. With a vector the surrounding elements are stored in the processors cache.

提交回复
热议问题