How can I parse through a large file in a fast and efficient way?

Recommended Answers

All 3 Replies

Is it text or binary? What operating system and what compiler?

Text,
Window 7,
VC++ 2010

The only way to process text files is to read them sequentially, start to finish. Text files generally don't allow for random access. One trick I've used in the past with text files which must be read frequently is to set up a fixed-length record index file which contains line numbers and the offset in the file where the line number begins. This only speeds up frequently reading the file, not writing. You have to completly rewrite the file if the new text is longer or shorter than the existing text. For example you can't just simply overwrite the word "the" with the word "them". But if you want to overwrite "the" with anothr 3-letter word then you can just overwrite it, assuming you know the offset of the start of the word.

A better answer to your question will depend on what you mean by "process the file". It might mean that you need to read a block of lines into memory, process them, and rewrite them to another file, then repeat that until the entire file is processed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.