I want binary compare
I want to compare two equal sized files byte to byte. In fact I did this with Delphi(via TMemoryStream) but wanted a more quick compare. So tried via BC++Compiler(commandline - as "C" & "API"). But I am very confused. Delphi did approx. 30 times faster. I used, CreateFile, SetFilePointer and ReadFile API func. for this. And one more tried to add VirtualAlloc even but thats slower :( In fact here is my code(more clear.) What is wrong code or compiler. Finishing time is too different.
(note: some controller codes removed. mem, file etc.)
void Compare(HWND _hwnd)
DWORD bayt1 = 0;
DWORD bayt2 = 0;
DWORD numofbyts = 0;
hFile1=CreateFile(szFile1,GENERIC_READ + GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
hFile2=CreateFile(szFile2,GENERIC_READ + GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
MessageBox (NULL, "bla" , "Err", 0 + MB_ICONHAND);
for (unsigned int i=0;i<size1;i++)
SetFilePointer(hFile1, i, NULL, FILE_BEGIN);
SetFilePointer(hFile2, i, NULL, FILE_BEGIN);
MessageBox (_hwnd, "Files Closed" , "Result", 0 + MB_ICONASTERISK);
It's simple, your algorithm sucks!
1) You are reading a byte at a time for gods sake! File I/O is really slow, load a block into memory and compare it.
2) You are resetting the file pointer every time you loop when you really dont need to.
3) use CODE tags when you post.
this is the kind of thing you want to do
hope this helps
BYTE buffer1 = new BYTE[size1];
BYTE buffer2 = new BYTE[size1];
ReadFile(hFile1, buffer1, size1, &numofbyts, NULL);
ReadFile(hFile2, buffer2, size1, &numofbyts, NULL);
BOOL same = memcmp(buffer1, buffer2, size1) == 0;
PS. i didn't compile the above code, it's intended to give you an idea.
I know the code sucks. Because I used what I found in winapi help files. I am learner. And learned this time. So... anyway thaks.
(btw please don't use such words.)
hey, i wasn't having a go at ya.. i was just being frank. I'm not one to beat about the bush, you wanted help, you got it. Don't take it so personally.
if you learned from it, then mission accomplished! you wanted to learn, and i wanted to teach.
no hard feelings eh!?
OK. I suppose it was my bad day. And I am not accustomed to such things. I forgot. Btw, I wanted to do this byte to byte, so it was different. But I solved this via mapping both files to mem. So, now very very quick and I can store all address, orijinal and different bytes.