Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Byte Array

Posted on 2011-09-30
4
Medium Priority
?
369 Views
Last Modified: 2012-06-22
Wheat is the best way to check a byte array to see if it has changed, I have the following property

    Public Property MergeDocument() As Byte()
        Get
            Return _mergeDocument
        End Get
        Set(ByVal value As Byte())
            If _mergeDocument ??? value Then
                If Not Loading Then
                    _isDirty = True
                End If
                _mergeDocument = value
            End If
        End Set
    End Property

I also need to do a check to see if it is empty, is it best to just use .Count?
0
Comment
Question by:rocky050371
  • 2
4 Comments
 
LVL 18

Expert Comment

by:lludden
ID: 36891483
If both arrays are already in memory, you can just use a compare function:

http://stackoverflow.com/questions/627742/what-is-the-fastest-way-to-compare-two-byte-arrays/627767#627767
Public Shared Function ArraysEqual(ByVal first As Byte(), _
                                   ByVal second As Byte()) As Boolean
    If (first Is second) Then
        Return True
    End If

    If (first Is Nothing OrElse second Is Nothing) Then
        Return False
    End If
    If  (first.Length <> second.Length) Then
         Return False
    End If

    For i as Integer = 0 To first.Length - 1
        If (first(i) <> second(i)) Then
            Return False
        End If
    Next i
    Return True
End Function

Open in new window


If you have to read one of them from storage, it would be better to use a stream and only read in enough of it/them to prove inequality.
0
 

Author Comment

by:rocky050371
ID: 36891544
 If (first Is Nothing OrElse second Is Nothing) Then
        Return False
    End If

Surely if they are both empty then an incorrect value would be returned

Is the following based on them both pointing to the same memory address

  If (first Is second) Then
        Return True
    End If

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36891581
0
 
LVL 18

Expert Comment

by:lludden
ID: 36891589
You can add in
If First Is Nothing AND Second Is Nothing) Then
    Return True
End if

(do it before the comparison you listed)

Yes.  If you are comparing an object to itself, it will always be equal.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question