Skip to main content
Question Protected by Pavneet_Singh
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

How can I do this fast?

Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i=0; i<a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}

But I'm looking for either a BCL function or some highly optimized proven way to do this.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

Note my super-fast answer herehere.

How can I do this fast?

Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i=0; i<a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}

But I'm looking for either a BCL function or some highly optimized proven way to do this.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

Note my super-fast answer here.

How can I do this fast?

Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i=0; i<a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}

But I'm looking for either a BCL function or some highly optimized proven way to do this.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

Note my super-fast answer here.

Copy edited. Added some context. Removed meta (this belongs in comments). Removed historical information (e.g. ref. <http://meta.stackexchange.com/a/230693> and <http://meta.stackoverflow.com/questions/266164>).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

How can I do this fast? Sure

Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2) 
{
    if (a1.Length !=a2= a2.Length)
        return false;

    for (int i=0; i<a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}

butBut I'm looking for either a BCLBCL function or some highly optimized proven way to do this.

[Edit]Thanks to JasonBunting and aku for their input.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

[Edit] Note my super-fast answer here.

How can I do this fast? Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2) 
{
  if(a1.Length!=a2.Length)
    return false;

  for(int i=0; i<a1.Length; i++)
    if(a1[i]!=a2[i])
      return false;

  return true;
}

but I'm looking for either a BCL function or some highly optimized proven way to do this.

[Edit]Thanks to JasonBunting and aku for their input.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

[Edit] Note my super-fast answer here.

How can I do this fast?

Sure I can do this:

static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i=0; i<a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}

But I'm looking for either a BCL function or some highly optimized proven way to do this.

java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);

works nicely, but it doesn't look like that would work for x64.

Note my super-fast answer here.

Great answer.. now it's searchable by tags...
Link
makerofthings7
  • 61.8k
  • 57
  • 232
  • 467
added 99 characters in body; deleted 31 characters in body; added 40 characters in body; deleted 9 characters in body
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading
moved my answer to an answer and accepted it to make it clear which one I preferred.
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading
edited tags
Link
Daniel Jennings
  • 6.5k
  • 3
  • 34
  • 44
Loading
added 163 characters in body
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading
edited body
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading
added 994 characters in body
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading
Source Link
Hafthor
  • 17k
  • 9
  • 59
  • 66
Loading