Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TStream.Position compared to TStream.Seek

Tags:

delphi

To move the "current byte" pointer in TStream class we can use property Position (e.g. MyStream.Position := 0) or using Seek method (e.g. MyStream.Seek(0, soFromBeginning). The question is, which one is more efficient (aka faster)? (I don't have the source, so I could not check it myself).

So far I always use Seek in positioning that said pointer.

like image 859
Luthfi Avatar asked Oct 07 '10 13:10

Luthfi


1 Answers

As TStream.Seek is an overloaded function handling 32-Bit or 64-Bit values, it depends on the current stream implementation, which might be the better choice.

For instance TCustomMemoryStream implements the 32-Bit version of Seek(). When you set Position on that stream this will first call the 64-Bit version, which casts the value to a Longint while calling the 32-Bit version. (This will probably change with a 64-Bit version of Delphi!)

On the other hand a THandleStream implements the 64-Bit version of Seek(). When you call Seek() with a 32-Bit value you end up in a quite nasty mechanism calling the 64-Bit version.

My personal advice would be to set Position. At least it will be the better choice in the future.

like image 163
Uwe Raabe Avatar answered Nov 04 '22 15:11

Uwe Raabe