Page 1 of 1
Comparememory() return Value [Done]
Posted: Mon Jul 29, 2019 9:08 am
by collectordave
Can the compareMemory() return value be modyfied so that when comparing memory areas the return value is 0 when they are the same and the byte number beginning at 1 of the first byte that does not match?
Maybe just use this:-
Code: Select all
Procedure.l CompareMemoryByte(*Mem1,Mem2,Length.l)
Define Pointer.l
For Pointer = 0 To Length
If PeekA(*mem1 + Pointer) <> PeekA(*mem1 + Pointer)
ProcedureReturn Pointer
EndIf
ProcedureReturn -1
EndProcedure
CD
Re: Comparememory() return Value
Posted: Mon Jul 29, 2019 9:18 am
by NicTheQuick
So you need FindString() but for binary data?
Unfortunality there is no such command available but you could try to implement your own or search in the board for a similar approach. I remember seeing such a procedure in the past. Maybe an other member knows where it is.
Re: Comparememory() return Value
Posted: Mon Jul 29, 2019 9:25 am
by idle
Wilbert's Module FindData
viewtopic.php?f=12&t=62519
Re: Comparememory() return Value
Posted: Mon Jul 29, 2019 9:32 am
by Little John
collectordave wrote:Can the compareMemory() return value be modyfied so that when comparing memory areas the return value is 0 when they are the same and the byte number beginning at 1 of the first byte that does not match?
That's not a good idea, because it would break existing code. What you need is another function.
idle was quicker ...
Anyway, in cases like this it's always a good idea to search the forum for "wilbert".
Or perhaps a simple function like the following might be sufficient:
Code: Select all
Procedure.i MemoryDiff (*mem1.Byte, *mem2.Byte, size.i)
; -- simple byte by byte comparison of two memory areas
; in : *mem1, *mem2: pointers to the memory areas
; size : number of bytes to compare
; out: offset where the first difference is, or
; -1 if both areas are identical or
; -2 on error
Protected offset.i, last.i=size-1
If *mem1 = 0 Or *mem2 = 0 Or size < 0
ProcedureReturn -2
ElseIf *mem1 = *mem2
ProcedureReturn -1
EndIf
For offset = 0 To last
If *mem1\b <> *mem2\b
ProcedureReturn offset
EndIf
*mem1 + 1
*mem2 + 1
Next
ProcedureReturn -1
EndProcedure
Re: Comparememory() return Value
Posted: Mon Jul 29, 2019 10:03 am
by collectordave
Updated first post with little procedure to do it.
Thanks for all your replies.
regards
CD
Re: Comparememory() return Value
Posted: Mon Jul 29, 2019 8:12 pm
by mk-soft
First make sense with a huge amount of data.
Move to General Discussion
Link:
viewtopic.php?f=7&t=73297
Re: Comparememory() return Value
Posted: Tue Jul 30, 2019 3:40 am
by collectordave
Nice one.
Just what I needed.
CD
Re: Comparememory() return Value [Done]
Posted: Tue Jul 30, 2019 4:14 am
by Tenaja
With large data it will be faster to test long integers instead of bytes, then just do bounds testing and find within the failed integer to find the byte.