Comparing 2 files.
BlitzMax Forums/BlitzMax Beginners Area/Comparing 2 files.
| ||
| Hi, I've loaded alot of small tile images into the memory and I want to compare them to each other to remove any duplicates. I'm looping through them, but I have no idea on how to compare these 2 memory blocks to each other so to speak :P Any idea on how I'd do this? :O Thanks! :D |
| ||
SuperStrict
Extern "C"
Function memcmp:Int(First:Byte Ptr, second:Byte Ptr, bytecount:Int)
End extern
Local img1:TImage = LoadImage("test1.png")
Local img2:TImage = LoadImage("test2.png")
Local pix1:TPixmap = LockImage(img1)
Local pix2:TPixmap = LockImage(img2)
If memcmp(pix1.Pixels, pix2.Pixels, Max(pix1.Capacity, pix2.Capacity)) = 0 Then
Print "pixels match!"
Else
Print "No match!"
End If
UnlockImage(img1)
UnlockImage(img2) |
| ||
| Thanks Zeke! :) This is Win only or? I'd prefer a non-extern way of doing this aswell if there is one :O |
| ||
| memcmp is standard c-command so this is not windows only. and using extern i think this is the easiest way to compare memory blocks.. this command should be added to bmax, because bmax have MemAlloc,MemCopy etc commands. |
| ||
| Okey, Great! :) It works like a charm, Thanks alot Zeke! |
| ||
| Hmmm...I know I kinda missed the train here but I am using a different approach when using lots of tiles using the same image to save memory. The image is probably connected to a type which contains an image like this: If you know that you will have many tiles that uses the same image, instead of loading the image again, which will allocate more memory, it's better to use a templateimage that you only load once. Just remember that if you delete templateimage the game/app will crash since the other instances is pointing towards templateimage. |