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

前端 未结 3 1135
情歌与酒
情歌与酒 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:22

    Consider turning into the vector directly into an array .. the below will work and be valid, until you resize the vector.

    vector vec(10); int *array = &vec[0];

    Then, you should be able to treat that (I think -- VS not on machine) as a passed array to populate your list.

    You should also create your list with a size that you expect to need -- adding one by one will be slow.

提交回复
热议问题