作者:admin 来源: 日期:2020/10/11 21:07:28 人气: 标签:
请确保您使用的是FastMM4-这样可以加快速度。内存分配很多。如果您只读取一次文件,则可以根据需要继续使用旧的“ TextFile”处理。只需添加一些更大的读取缓冲区,并摆脱I / O检查即可:
var sourceFile : textFile; line : string; fields : TinputList; buf: array[word] of byte; // 64 KB buffer begin fields:=TinputList.create; AssignFile(sourceFile,filename); SetTextBuf(sourceFile,buf); // will speed up reading Reset(sourceFile); {$I-} // if we reached here, the file is existing while NOT EOF(sourceFile) do begin ReadLn(sourceFile,line); fields.loadFromCommaLine(line); // process the fields of this record end; {$I+} closeFile(sourceFile); fields.free; end;
默认情况下,缓冲区为128字节,这非常小,并且会经常调用Windows文件API:这是较慢的部分。
仅使用64 KB即可大大提高速度。ReadLn()函数速度很快,尤其是当您的行少于256个字节时。
如果要随机访问文件内容,可以通过“内存映射”窗口读取文件。
它非常快速且方便,但是在32位处理下,您将无法一次映射3GB的文件(根据我的实验,最多可以映射500 MB或更少,具体取决于您当前的内存使用情况) 。因此,您必须使用“窗口”,该窗口有意在文件上滑动。