|
-
Nov 4th, 2005, 07:46 AM
#1
Thread Starter
Lively Member
RtlCompareMemory Help please[RESOLVED]
Hi all, Please could someone tell me how i use the RtlCompareMemory api to compare 2 2d arrays.
Thanks in advance...
Last edited by Adrian26; Nov 7th, 2005 at 04:11 AM.
-
Nov 4th, 2005, 09:02 AM
#2
Re: RtlCompareMemory Help please
I'm sure you have a more imaginative example in mind, but here:
(Note, this is very ugly, and could be optimised by storing LBound/UBound values. Even better, use zero-based dimensions exclusively, that will be much faster overall).
VB Code:
Private Declare Function RtlCompareMemory Lib "ntdll" ( _
ByRef Source1 As Any, _
ByRef Source2 As Any, _
ByVal Length As Long _
) As Long
'
Private Sub Command1_Click()
Dim array1(3, 6) As Long
Dim array2(3, 6) As Long
array1(2, 4) = 50
array2(2, 4) = 50
' Usage to compare two 2D arrays:
Dim size1 As Long, size2 As Long
size1 = (UBound(array1, 1) - LBound(array1, 1)) * _
(UBound(array1, 2) - LBound(array1, 2)) * _
LenB(array1(LBound(array1, 1), LBound(array1, 2)))
size2 = (UBound(array2, 1) - LBound(array2, 1)) * _
(UBound(array2, 2) - LBound(array2, 2)) * _
LenB(array2(LBound(array2, 1), LBound(array2, 2)))
If (size1 = size2) Then
If (RtlCompareMemory(ByVal VarPtr(array1(LBound(array1, 1), LBound(array1, 2))), _
ByVal VarPtr(array2(LBound(array2, 1), LBound(array2, 2))), _
size1) = size1) _
Then
MsgBox "Arrays are equal"
Else
MsgBox "Arrays are not equal"
End If
Else
MsgBox "Arrays have different dimensions"
End If
End Sub
-
Nov 4th, 2005, 09:05 AM
#3
Re: RtlCompareMemory Help please
If you do use zero-based dimensions, it is a hell of a lot neater.
VB Code:
Dim size1 As Long, size2 As Long
size1 = UBound(array1, 1) * UBound(array1, 2) * LenB(array1(0, 0))
size2 = UBound(array2, 1) * UBound(array2, 2) * LenB(array2(0, 0))
If (size1 = size2) Then
If (RtlCompareMemory(ByVal VarPtr(array1(0, 0)), _
ByVal VarPtr(array2(0, 0)), _
size1) = size1) _
Then
MsgBox "Arrays are equal"
Else
MsgBox "Arrays are not equal"
End If
Else
MsgBox "Arrays have different dimensions"
End If
-
Nov 4th, 2005, 10:22 AM
#4
Re: RtlCompareMemory Help please
Penagate,
You and Joacim like varptr don't you?
VB Code:
If RtlCompareMemory(array1(0, 0), array2(0, 0), size1) = size1 then
-
Nov 4th, 2005, 10:29 AM
#5
Re: RtlCompareMemory Help please
-
Nov 7th, 2005, 03:58 AM
#6
Thread Starter
Lively Member
Re: RtlCompareMemory Help please
Excellent! works like a dream many thanks...
One last question though, the way you work out the array sizes can i use the same method for the copyMemory api, again the arrays are 2d.
Cheers...
-
Nov 7th, 2005, 04:00 AM
#7
Re: RtlCompareMemory Help please
-
Nov 7th, 2005, 04:10 AM
#8
Thread Starter
Lively Member
Re: RtlCompareMemory Help please
Now that was a fast reply, thanks once again.
-
Nov 7th, 2005, 04:13 AM
#9
Re: RtlCompareMemory Help please[RESOLVED]
No problem!
-
Nov 7th, 2005, 05:06 AM
#10
Re: RtlCompareMemory Help please[RESOLVED]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|