我有这样一个列表:C++中的列表
list<int> p[15];
list<int> copy_of_p[15];
Run Code Online (Sandbox Code Playgroud)
C#中的列表
list<int>[15] p;
list<int>[15] copy_of_p;
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码在C#中制作10000份副本
for (int counter = 0; counter < 15; counter++)
{
copy_of_p[counter] = p[counter].toList();
}
Run Code Online (Sandbox Code Playgroud)
花了大约10 MiliSecs
然后我用这段代码在c ++中做了同样的事情
for (int counter = 0; counter < 15; counter++)
{
copy_of_p[counter] = p[counter];
}
Run Code Online (Sandbox Code Playgroud)
它花了大约1200 MiliSecs
这意味着在c ++中应该有一种方法来复制列表至少与C#一样快.你能指导我扔这个吗?
PS:我试过了
copy(p.begin(), p.end(), copy_of_p[counter]);
Run Code Online (Sandbox Code Playgroud)
但它造成了构建错误
请记住,stl-list <>与C#List <>不同.stl-list是双向链表,而C#List <>将数据存储在一个有条件的内存块中.因此stl-list <>复制操作要快得多.
C#List <>等同于stl-vector <>
stl-list等同于C#LinkedList <>