It is currently Mon Sep 23, 2019 6:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Comparememory() return Value [Done]
PostPosted: Mon Jul 29, 2019 9:08 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1013
Location: Portugal
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:
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

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Last edited by collectordave on Tue Jul 30, 2019 3:41 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Mon Jul 29, 2019 9:18 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 426
Location: Germany, Saarbrücken
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.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Mon Jul 29, 2019 9:25 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3392
Location: New Zealand
Wilbert's Module FindData

viewtopic.php?f=12&t=62519


Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Mon Jul 29, 2019 9:32 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
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:
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

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Mon Jul 29, 2019 10:03 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1013
Location: Portugal
Updated first post with little procedure to do it.

Thanks for all your replies.

regards

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Mon Jul 29, 2019 8:12 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1914
Location: Germany
First make sense with a huge amount of data.

Move to General Discussion
Link: viewtopic.php?f=7&t=73297
Code:
... Move

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Tue Jul 30, 2019 8:46 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value
PostPosted: Tue Jul 30, 2019 3:40 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1013
Location: Portugal
Nice one.

Just what I needed.

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Comparememory() return Value [Done]
PostPosted: Tue Jul 30, 2019 4:14 am 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1529
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye