数组^ 和 byte* 之间有什么区别?
是否可以强制转换数组<字节>^ 到字节*?
下面的代码需要如何更改才能返回一个字节*?
array<Byte>^ StrToByteArray(System::String^ unicodeString)
{
UTF8Encoding^ utf8 = gcnew UTF8Encoding;
array<Byte>^ encodedBytes = utf8->GetBytes( unicodeString );
return encodedBytes;
}
And is it possible to cast the array< Byte>^ to an byte*?
how would the below code need to changed to return a byte*?
array<Byte>^ StrToByteArray(System::String^ unicodeString)
{
UTF8Encoding^ utf8 = gcnew UTF8Encoding;
array<Byte>^ encodedBytes = utf8->GetBytes( unicodeString );
return encodedBytes;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
array^ 是托管堆中对象的句柄,byte* 是指向非托管字节的指针。您不能在它们之间进行转换,但可以修复托管数组并获取指向其中元素的指针。
编辑回应第一条评论:
这是取自msdn 上的此页面
您最感兴趣的是 void Load() 方法。在这里,他们固定数组,并获取指向其中第一个元素的指针......
array^ is a handle to an object in the managed heap, byte* is a pointer to an unmanaged byte. You cannot cast between them, but it is possible to fix the managed array and obtain a pointer to the elements within it.
EDIT in response to first comment:
Here's a code sample taken from this page on msdn
The bit you are most interested in is the void Load() method. Here they are pinning the array, and taking a pointer to the first element in it...
不,你不能转换它,但 array 有一个方法可以返回原始数组,称为“data()”
编辑:nvm,以为你在谈论 stl 类数组。
No, you cannot cast it, but array has a method that returns the raw array called "data()"
EDIT: nvm, thought you were talking about the stl class array.