Delphi 6 支持大文件吗? (替换系统模块?)
我在与巨大的固定长度记录数据文件交互时遇到问题。该文件大小超过 14 GB。当我看到 System.Filesize() 函数的返回值远小于大文件中的实际记录数(考虑到文件中的字节数和每条记录的长度。 (System.Filesize 返回非类型化文件中给定 Reset()
调用期间指定的记录大小的记录数。它不返回文件中的字节数)。我将其归因于 System.Filesize()
的返回类型是 Longint 而不是 Int64。
我通过调用 GetFileSizeEx() 并自己计算记录数来解决最初的问题。不幸的是,当尝试访问文件中偏移量深入文件的记录时,BlockRead()
也会失败。我猜测代码中的某个地方再次使用了溢出的值。
Delphi 6 是否有一个替代模块可以处理大文件并且可以替代系统单元文件 I/O 调用?如果可以的话,我会尽量避免自己动手。
I am running into problems interacting with a huge fixed length record data file. The file is over 14 GB in size. I first noticed a problem when I saw the return value from the System.Filesize()
function was far less than the actual number of records in the huge file, given the number of bytes in the file and the length of each record. (System.Filesize returns the number of records in an untyped file given the record size specified during the Reset()
call. It does not return the number of bytes in the file). I chalked it up to the return type of System.Filesize()
being a Longint instead of an Int64.
I worked around the initial problem by calling GetFileSizeEx()
and calculating the number of records myself. Unfortunately, BlockRead()
also fails when trying to access records in the file whose offset is deep into the file. I'm guessing that again there are values being used that are overflowing somewhere in the code.
Is there a replacement module out for Delphi 6 there that can handle huge files and is a substitute for the System unit file I/O calls? I'm trying to avoid rolling my own if I can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
GpHugeFile
来自 Primoz Gabrijelcic。我自己使用这个库从 Delphi 7 访问更大的文件(> 2GB)。无论如何,在您的情况下,您必须考虑尝试更改应用程序逻辑并迁移到数据库方案,该方案比基于记录文件的方案要高效得多。You can use the
GpHugeFile
from Primoz Gabrijelcic. I used this library myself to access larger files (> 2gb) from Delphi 7. Anyway in your case you must consider try to change you app logic and migrate to a Database scheme which is much more efficient which a scheme based in record files.尝试TGpHugeFile。
Try TGpHugeFile.
事实证明,由于使用低容量数字类型,系统单元使用的内部搜索例程也存在问题。我编写了自己对 Windows SetFilePointerEx() 函数的调用,一切都很好。我提供了下面的源代码,以防对其他人有所帮助。我也包含了我创建的用于正确获取记录数量的代码,因为您将需要两者。其他一切都一样。
It turns out that the internal seek routine used by the System unit also had problems due to the use of low capacity numeric types. I coded up my own call to the Windows SetFilePointerEx() function and all is well. I have provided the source code below in case it might help others. I have included the code I created to get the number of records properly too since you will need both. Everything else works the same.
您不能将 Pascal I/O 与这样的大文件一起使用,在任何版本的 Delphi 中都不能。最好的选择是使用没有此类限制的
TFileStream
。You can't use Pascal I/O with huge files like this, not in any version of Delphi. Your best bet is to use a
TFileStream
which has no such limitations.