Created
October 1, 2022 09:10
-
-
Save zedxxx/ff8d671b2ccff3f762af7bd32fb19863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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