Silverlight 5 中 UnsafeAddrOfPinnedArrayElement 的等效项
我正在尝试将一些 pInvoke 方法调用转换为 Silverlight 5,但遇到了问题。我将如何执行与在 Silverlight 5 中调用 UnsafeAddrOfPinnedArrayElement 等效的操作?
public int Read(byte[] buffer, int index, int length)
{
var gch = GCHandle.Alloc(buffer);
try
{
//Desktop .NET Framework code:
//var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index);
//WHAT IS THE SL 5 Equivalent here?
//TODO Call some pinvoke code that requires 'ptr'
}
finally
{
gch.Free();
}
}
I'm trying to convert some pInvoke method calls to Silverlight 5 but have come up against a problem.How would I do the equivalent of calling UnsafeAddrOfPinnedArrayElement in Silverlight 5?
public int Read(byte[] buffer, int index, int length)
{
var gch = GCHandle.Alloc(buffer);
try
{
//Desktop .NET Framework code:
//var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index);
//WHAT IS THE SL 5 Equivalent here?
//TODO Call some pinvoke code that requires 'ptr'
}
finally
{
gch.Free();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我读到的内容来看,UnsafeAddrOfPinnedArrayElement 只是获取数组中元素的内存地址,为什么不自己实现呢?您还可以避免再次分配整个缓冲区......
From what I'm reading UnsafeAddrOfPinnedArrayElement is just getting the memory address of an element in an array, why not just implement it yourself? You'll also avoid having to allocate the entire buffer a second time...