@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm Summary: Very fast comparison of byte arrays. !!!!C# Signature: [DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)] static extern int memcmp(byte[] b1, byte[] b2, UIntPtr count); !!!!Alternative Managed API: Enumerable.SequenceEqual see: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.sequenceequal.aspx !!!!Notes: WARNING: For x86 and x64 platform compatibility make sure to specify the Cdecl calling convention and use the UIntPtr type to correctly marshall the size_t count argument. !!!!Tips & Tricks: When calling memcmp via pinvoke there is no need to use unsafe code or pinning because the framework will automatically pin the arrays for you. !!!!Sample Code: !!!!! Example: //Extension Method example public static class ByteArrayExtensions { [DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)] private static extern int memcmp(byte[] b1, byte[] b2, UIntPtr count); public static bool SequenceEqual(this byte[] b1, byte[] b2) { if (b1 == b2) return true; //reference equality check if (b1 == null || b2 == null || b1.Length != b2.Length) return false; return memcmp(b1, b2, new UIntPtr((uint)b1.Length)) == 0; } } !!!!Edits: Added (x86 and x64) signature and example. Removed SetLastError attribute from bottom 2 signatures as memset does not use this API. Removed confusing signatures Documentation: memcmp@msdn on MSDN
Edit msvcrt.memcmp
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.