Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
Delphi 10.2 Tokyo Professional
|
Re: Eindeutiger Vergleich für große Dateien gesucht
3. Aug 2005, 18:21
Ich will mal nicht unken, aber 0,20 Sekunden KANN NICHT SEIN, bei keiner Festplatte der Welt!
[Nachtrag]
Modifizier die Routine mal so (rote Stellen), dann bekommst du mit, ob ein Fehler aufgetreten ist (was ich mir denke):
Code:
function CompareFilesMemoryMapped(const File1, File2: String; SysAllocSize: Cardinal): [color=red]integer[/color];
var
CurSize: DWord;
CurPos: Int64;
hFile1, hFile2: THandle;
hMap1, hMap2: THandle;
FileSize: Int64;
P1, P2: Pointer;
begin
[color=red]Result := -1;[/color]
hFile1 := CreateFile(@File1[1], GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
if hFile1 <> INVALID_HANDLE_VALUE then
try
hFile2 := CreateFile(@File2[1], GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
if hFile2 <> INVALID_HANDLE_VALUE then
try
FileSize := GetHugeFileSize(File1); //GetFileSizeInt64(hFile1);
if FileSize = GetHugeFileSize(File2) then //GetFileSizeInt64(hFile1) then
begin
Result := True;
if FileSize > 0 then
begin
hMap1 := CreateFileMapping(hFile1, nil, PAGE_READONLY, 0, 0, nil);
if hMap1 <> INVALID_HANDLE_VALUE then
try
hMap2 := CreateFileMapping(hFile2, nil, PAGE_READONLY, 0, 0, nil);
if hMap2 <> INVALID_HANDLE_VALUE then
try
CurSize := FileSize mod SysAllocSize;
if CurSize = 0 then
CurSize := SysAllocSize;
CurPos := FileSize - CurSize;
repeat
P1 := MapViewOfFile(hMap1, FILE_MAP_READ, Int64Rec(CurPos).Hi, Int64Rec(CurPos).Lo, CurSize);
if P1 <> nil then
try
P2 := MapViewOfFile(hMap2, FILE_MAP_READ, Int64Rec(CurPos).Hi, Int64Rec(CurPos).Lo, CurSize);
if P2 <> nil then
try
[color=red]if CompareMem(P1, P2, CurSize)
then Result := 1
else Result := 0;[/color]
finally
UnmapViewOfFile(P2);
end; // else RaiseLastWin32Error;
finally
UnmapViewOfFile(P1);
end; // else RaiseLastWin32Error;
CurPos := CurPos - CurSize;
CurSize := SysAllocSize;
until
(CurPos <= 0) or (not Result);
finally
CloseHandle(hMap2);
end; // else RaiseLastWin32Error;
finally
CloseHandle(hMap1);
end; // else RaiseLastWin32Error;
end;
end;
finally
CloseHandle(hFile2);
end; // else RaiseLastWin32Error;
finally
CloseHandle(hFile1);
end; // else RaiseLastWin32Error;
end;
Volker
|