Why is this so much slower in C++?

后端 未结 9 2006
盖世英雄少女心
盖世英雄少女心 2020-12-31 11:49

I have converted this simple method from C# to C++. It reads a path table and populates a list of lists of ints (or a vector of vectors of ints).

A sample line from

9条回答
  •  醉梦人生
    2020-12-31 12:29

    Haven't tested the code but how many ints does it typically load? Consider what happens when each of your vectors reaches its capacity. A vector grows inefficiently - O(n) I believe. C#'s List doesn't have this behaviour.

    Consider using std::deque, std::list or some other container that has better growth behaviour. See this article for more info.

提交回复
热议问题