System::String 到 char* 并在 C++/CLI 中返回:比 Marshal 更快?
在 C++/CLI 项目 (Visual Studio 2010) 中,将 System::String 转换为 char* 以便可以将其发送到系统函数,并类似地将接收到的 char* 转换为 System::String 的最佳方法是什么?
有没有比使用 System::Runtime::InteropServices::Marshal 类更快的方法?
In a C++/CLI project (Visual Studio 2010), what is the best way to convert a System::String to a char* so it can be sent to a system function, and similarly convert the received char* to System::String?
Is there a faster way than using the System::Runtime::InteropServices::Marshal class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
char*
还是wchar_t*
?const
或否?如果您真正需要的是const wchar_t*
您可以使用PtrToStringChars
来自 vcclr.h,这不会导致任何无意中的复制(但是您仍然需要固定结果)。换句话说,您可能无法明显击败
Marshal
,但System::String
确实具有采用指针的构造函数。char*
orwchar_t*
?const
or no? If what you really need is aconst wchar_t*
you can do it pretty quick withPtrToStringChars
from vcclr.h which won't incur any copying overheard (you'll need to pin the result still however).Going the other way you're probably not going to be able to significantly beat
Marshal
,System::String
does have constructors that take pointers though.