C#内存复制与比较

比较:

 public static extern int comp2(byte[] a, byte[] b, int count);
        [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
        static extern int memcmp(byte[] b1, byte[] b2, UIntPtr count);
        [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
        static extern int memcmp(IntPtr ptr1, IntPtr ptr2, int count);
        [DllImport("msvcrt.dll",  CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
        static extern unsafe int memcmp(void* ptr1, void* ptr2, int count);

复制:

   [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
        public static extern IntPtr memcpy(IntPtr dest, IntPtr src, UIntPtr count);
        [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
        public static extern IntPtr MemCopy(byte[] dest, byte[] src, UIntPtr count);
 

还有一个复制的方法:

 System.Runtime.InteropServices.Marshal.Copy(buffer, bytes, 0, size)
 

原文地址:https://www.cnblogs.com/81/p/2289025.html