What is the most efficient way to convert a std::vector to a .NET List?

前端 未结 3 1143
情歌与酒
情歌与酒 2021-02-14 01:38

What is the most efficient way to convert a std::vector to a .NET List?

To give some context, I am wrapping an unmanaged C++ class with C++/CLI. The C++/CLI class holds

3条回答
  •  故里飘歌
    2021-02-14 02:21

    I am not familiar with C++-CLI but one small improvement you can make is to create your list with the right capacity from the beginning.

    List list = gcnew List(runList.size());
    

    Another improvement would be to pre-increment your C++ iterator instead of post-incrementing it because currently you create an extra object for every element that is discarded immediately.

提交回复
热议问题