TStream.Position与TStream.Seek的比较 [英] TStream.Position compared to TStream.Seek

查看:193
本文介绍了TStream.Position与TStream.Seek的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在TStream类中移动当前字节指针,我们可以使用位置属性(例如MyStream.Position:= 0)或使用Seek方法(例如MyStream.Seek(0,soFromBeginning)。问题是,哪个是

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).

到目前为止,我一直使用Seek来定位

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

推荐答案

由于 TStream.Seek 是重载的函数,处理32或64位值,它取决于当前的流实现,这可能是更好的选择。

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.

例如 TCustomMemoryStream 实现32位版本的 Seek()。在该流上设置 Position 时,首先调用64位版本,然后在调用32位版本时将值转换为Longint(这可能会随Delphi的64位版本而改变!)

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!)

另一方面,有一个 THandleStream 实现nts Seek()的64位版本。当您使用32位值调用 Seek()时,您会遇到一种非常讨厌的机制,称为64位版本。

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.

我个人的建议是设置 Position 。至少将来它将是更好的选择。

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

这篇关于TStream.Position与TStream.Seek的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆