I’m working with very large text files, 2GB and more. I would like to have a Seek() like function. Has anyone done something like that? Loading to TStringList is out of the question. Also working with untyped file as well. For now I’m using readLn, but that lasts too long. Thanks.
Share
Map the file into memory (CreateFileMapping/MapViewOfFile) by pieces, then scan the mapped memory and build an index – the list of positions of each line beginnings. Then your seek operation will be performed by getting position of Nth line in the file and seeking to this position. Use TFileStream then to perform random access to the file or, if you only read the file, you can use file mappings for random access as well – this might be even faster than using TFileStream in parallel to file mapping.