[fpc-devel] Memory Streams unable to handle reads past 2GB
Andrew
atbrunner at aurawin.com
Wed Nov 7 00:12:50 CET 2012
On 12-11-06 05:07 PM, Michael Van Canneyt wrote:
Please re-open the issue and I will post an updated program that fails
EVERY TIME.
Or just use the attached Widen.lpr... :-)
-------------- next part --------------
program Widen;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,SysUtils;
function Test_2(Count:LongInt; Factor:Byte):LongInt;
var
FSize:Int64;
FPosition:Int64;
begin
FPosition:=0;
FSize:=(1024*1024*1024)*Factor;
Result:=FSize-FPosition;
end;
function Test_1(Count:LongInt; Factor:Byte):Int64;
var
FSize:Int64;
FPosition:Int64;
begin
FPosition:=0;
FSize:=(1024*1024*1024)*Factor;
Result:=FSize-FPosition;
end;
function Test_3(Count:LongInt; Factor:Byte):LongInt;
const
MyBuffer:Array[0..1] of byte=(0,0);
var
FSize:Int64;
FPosition:Int64;
FS:TMemoryStream;
FWrote:LongInt;
FRead:LongInt;
begin
FS:=TMemoryStream.Create();
Try
FPosition:=0;
FSize:=(1024*1024*1024)*Factor;
While FPosition<FSize do begin
FWrote:=FS.Write(MyBuffer[0],2);
inc(FPosition,2);
end;
// Stream is filled
FS.Position:=0;
MyBuffer[0]:=1;
MyBuffer[1]:=2;
FRead:=FS.Read(MyBuffer[0],2);
If (FRead<>2) or (MyBuffer[0]<>0) or (MyBuffer[1]<>0) then
raise Exception.Create('Test_3 Failed');
Finally
FS.Free();
end;
end;
begin
Test_1(1024,1); //OK
Test_1(1024,2); //OK
Test_2(1024,1); //OK
//Test_2(1024,2); //Will always fail with range checking on
Test_3(1028,2); //will always fail with range checking on
end.
More information about the fpc-devel
mailing list