[fpc-pascal] TCustomStream still using LongInt and not Int64

Michael Van Canneyt michael at freepascal.org
Sun Dec 27 18:02:07 CET 2020



On Sun, 27 Dec 2020, Graeme Geldenhuys via fpc-pascal wrote:

> Hi,
>
> Is this a bug in FPC 3.2.0 where TCustomStream still uses LongInt in
> the Read() method, where all other methods in in the class uses Int64
> type?
>
> Here is the FPC code:
>
>  TCustomMemoryStream = class(TStream)
>  private
>    FMemory: Pointer;
>    FSize, FPosition: PtrInt;
>  protected
>    Function GetSize : Int64; Override;
>    function GetPosition: Int64; Override;
>    procedure SetPointer(Ptr: Pointer; ASize: PtrInt);
>  public
>    function Read(var Buffer; Count: LongInt): LongInt; override; // <-- Here
>    function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
>    ...
>  end;
>
>
> As this class extends the TStream class, I guess the issue relates to
> TStream too.
>
> eg: Why would you have GetSize(): Int64; or GetPosition: Int64; but when you
> read data, it is limited to the Longint type?

Because on 32 bit platforms, this is the maximum size of available memory for
a program, and we like things maximally portable. You can't read more than
2gb in memory on a 32-bit platform.

Seek, Size and position must support 64-bit, since the size of a file on
disk can of course be bigger than what 32-bit allows.


Michael.


More information about the fpc-pascal mailing list