What is the fastest way for reading huge files in Delphi?

Posted by dummzeuch on Stack Overflow See other posts from Stack Overflow or by dummzeuch
Published on 2011-01-06T13:19:25Z Indexed on 2011/01/06 13:53 UTC
Read the original article Hit count: 254

My program needs to read chunks from a huge binary file with random access. I have got a list of offsets and lengths which may have several thousand entries. The user selects an entry and the program seeks to the offset and reads length bytes.

The program internally uses a TMemoryStream to store and process the chunks read from the file. Reading the data is done via a TFileStream like this:

FileStream.Position := Offset;
MemoryStream.CopyFrom(FileStream, Size);

This works fine but unfortunately it becomes increasingly slower as the files get larger. The file size starts at a few megabytes but frequently reaches several tens of gigabytes. The chunks read are around 100 kbytes in size.

The file's content is only read by my program. It is the only program accessing the file at the time. Also the files are stored locally so this is not a network issue.

I am using Delphi 2007 on a Windows XP box.

What can I do to speed up this file access?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about file-io