I am currently trying to rewrite Binary Diff to support bigger files, as using GetMem
for reading files limits the file size (I suppose) and I am not able to read 2 files with a size of 900 MB each.
So I figured, I could use VirtualAlloc
, which sadly didn't work out so well yet. The allocation for the first file works fine from the looks of it - once I am trying to allocate memory for the second file, it returns a null pointer. Gotta say I am pretty new to allocating memory, so forgive me if I might have overseen a thread that already answers this question (I've searched the internet for a solution the past 4 hours).
Well, heres the code:
procedure TFileData.LoadFile;
var
FileHandle: Integer;
BytesRead: Integer;
dataPoint : Pointer;
begin
FileHandle := FileOpen(fName, fmOpenRead or fmShareDenyWrite);
try
if FileHandle = -1 then
Error('Cannot open file %s', [fName]);
fSize := GetFileSize(FileHandle, nil);
if fSize = Cardinal(-1) then
Error('Cannot find size of file %s - may be to large', [fName]);
if fSize = 0 then
Error('File %s is empty', [fName]);
try
dataPoint := VirtualAlloc(nil,fSize,MEM_COMMIT,PAGE_READWRITE);
fData := dataPoint;
BytesRead := FileRead(FileHandle, fData^, fSize);
if BytesRead = -1 then
Error('Cannot read from file %s', [fName]);
if fSize <> Cardinal(BytesRead) then
Error('Error reading from file %s', [fName]);
except
if Assigned(fData) then
FreeMem(fData, fSize);
raise;
end;
finally
if FileHandle <> -1 then
FileClose(FileHandle);
end;
end;
At the end of the day, I want to use the program to compare two nontext-files binarily of any size and create a Binary Diff from that.