.NET - Copy from Unmanaged Array to Unmanaged Array

元气小坏坏 提交于 2019-12-23 09:15:14

问题


I've been looking through the Marshal class, but I can't seem to find a method that allows me to copy from an unmanaged array (IntPtr) to another unmanaged array (IntPtr).

Is this possible using .NET?


回答1:


You can also DllImport RtlMoveMemory to get the job done:

[DllImport("Kernel32.dll", EntryPoint="RtlMoveMemory", SetLastError=false)]
static extern void MoveMemory(IntPtr dest, IntPtr src, int size);

This will also require FullTrust, however, but as you are working with unmanaged code, I'd expect you already have it.




回答2:


You can revert to using unsafe code in C#, if that is an option (typically requires FullTrust permission, which may not be available in all cases).



来源:https://stackoverflow.com/questions/3208101/net-copy-from-unmanaged-array-to-unmanaged-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!