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)
{
char *szFile1="file1.dat";
char *szFile2="file2.dat";
HANDLE hFile1,hFile2;
DWORD size1,size2;
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);
size1=GetFileSize(hFile1,0);
size2=GetFileSize(hFile2,0);
if(size1!=size2)
{
MessageBox (NULL, "bla" , "Err", 0 + MB_ICONHAND);
return;
}
for (unsigned int i=0;i<size1;i++)
{
SetFilePointer(hFile1, i, NULL, FILE_BEGIN);
ReadFile(hFile1,&bayt1,1,&numofbyts,NULL);
SetFilePointer(hFile2, i, NULL, FILE_BEGIN);
ReadFile(hFile2,&bayt2,1,&numofbyts,NULL);
if(bayt1!=bayt2) counter++;
}
CloseHandle(hFile1);
CloseHandle(hFile2);
MessageBox (_hwnd, "Files Closed" , "Result", 0 + MB_ICONASTERISK);
}
/////////////////////