Skip to content

Instantly share code, notes, and snippets.

@zedxxx
Created October 1, 2022 09:10
Show Gist options
  • Save zedxxx/ff8d671b2ccff3f762af7bd32fb19863 to your computer and use it in GitHub Desktop.
Save zedxxx/ff8d671b2ccff3f762af7bd32fb19863 to your computer and use it in GitHub Desktop.
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.Classes,
System.SysUtils;
const
CTestFileName = 'g:\test.bin';
procedure AllocBigFile;
begin
with TFileStream.Create(CTestFileName, fmCreate) do
try
Size := 300 * Int64(1024*1024 *1024); // 300 GB
finally
Free;
end;
end;
procedure DoTest;
var
VBuffer: TBytes;
VStream: TFileStream;
begin
VStream := TFileStream.Create(CTestFileName, fmOpenReadWrite);
try
VStream.Position := 300 * Int64(1024*1024*1024);
SetLength(VBuffer, 1);
VBuffer[0] := 42;
VStream.WriteBuffer(VBuffer, 0, 1);
VStream.Position := VStream.Position - 1;
VBuffer[0] := 0;
VStream.ReadBuffer(VBuffer[0], 1);
Assert(VBuffer[0] = 42);
finally
VStream.Free;
end;
end;
begin
try
AllocBigFile;
DoTest;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment