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)
 

posted @ 2011-12-15 16:02  81  阅读(608)  评论(0编辑  收藏  举报