1. different length arrays
2. buffer must be divisible by 4.
I simply check the remaining bytes using the two byte pointers.
Expand|Select|Wrap|Line Numbers
- public unsafe static bool CompareByteArrays(byte[] b1, byte[] b2)
- {
- if (b1.Length != b2.Length)
- return false;
- fixed (byte* bp1 = b1)
- {
- fixed (byte* bp2 = b2)
- {
- int* ip1 = (int*) bp1;
- int* ip2 = (int*) bp2;
- for (int i = 0; i < b1.Length/4; i++)
- {
- if (ip2[i] != ip1[i])
- return false;
- }
- if ((b1.Length % 4) != 0)
- {
- for (int i = b1.Length - (b1.Length % 4); i < b1.Length; i++)
- {
- if (bp2[i] != bp1[i])
- return false;
- }
- }
- return true;
- }
- }
- }
Peace,
Robb