我保留了内存10项128字节
IntPtr dst = Marshal.AllocHGlobal (10 * 128);
IntPtr src1 = Marshal.AllocHGlobal (128);
// .... init scr1 from DLL
IntPtr src2 = Marshal.AllocHGlobal (128);
// .... init scr2 from DLL
我需要复制 128 字节元素src1
and src2
to dst
在指定的偏移处。
元帅.副本不适合此类目的。
自从src
and dst
在非托管内存区域。
Window 的 API 函数memcopy http://www.pinvoke.net/default.aspx/msvcrt.memcpy应该可以解决问题。
[DllImport("msvcrt.dll", EntryPoint = "memcpy",
CallingConvention = CallingConvention.Cdecl,
SetLastError = false)]
public static extern IntPtr memcpy(IntPtr dest, IntPtr src, UIntPtr count);
另外,请检查一下:
https://stackoverflow.com/a/2658394/558018 https://stackoverflow.com/a/2658394/558018
正如它声称的那样,您可以使用unsafe
上下文来手动传输必要的字节。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)