Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-12

TCustomStream still using LongInt and not Int64

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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?

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 28 lines
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.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
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.

Ha yes, it's been so long since I ran a 32bit system, I forgot about the memory limits. :-) Thanks for the reminder.

I see that Delphi has now introduced a Read64() method into the TStream class. So they still keep backwards compatibility too, but allow for larger read operations.

http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TStream.Read64

Regards,
Graeme