且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C#中调用非托管c ++代码与STL混合

更新时间:2023-01-07 12:16:26

如果可能,您希望避免在纯UNB代码中使用STL。当你与C ++ / CLI(或Managed C ++)混合使用时,你最终可能会得到以托管方式运行的STL代码和以非托管方式运行的客户端代码。发生什么情况是,当你说,在一个向量上迭代时,每一次向量方法的调用都将转换为托管代码,然后再返回。

You want, if possible, to avoid using STL in anything but pure UNmanaged code. When you mix it with C++/CLI (or Managed C++), you will likely end up with the STL code running as managed and the client code running as unmanaged. What happens is that when you, say, iterate over a vector, every call to a vector method will transition into managed code and back again.

请参阅此处提出类似问题。