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
If you're really that concerned about it, use unverifiable code instead:
List^ MethodA()
{
std::vector const& runList = mpChannelNode->runList();
array^ ret = gcnew array(runList.size());
if (runList.size())
{
pin_ptr dest = &ret[0];
std::memcpy(dest, &runList[0], runList.size() * sizeof(unsigned));
}
return gcnew List(ret);
}
That said, I'd be surprised if there was a noticeable difference either way...