What is the most efficient way to read a big text file backwards, line by line, using Windows API functions? For example, if a file is:
line 1
...
line 108777
line 108778
the output should be:
line 108778
line 108777
...
line 1
I want to write a C program for this. You don't need to write a code (but if you want, that's great), I am just interested in how to do this having in mind that files are big and that I want program to run as fast as it can.
Also, I am interested in which Windows API functions to use.
A more clever solution is to open the file, set the file-offset to the (end of the file - buffersize) and read (buffersize) bytes, u can parse the data in the buffer from back to front to find newlines and do whatever you want, and so on.
If performance is more important than memory utilization, I'd just do a buffered read of the entire text file into memory and then parse it in whatever order you like.
Take a look at memory mapped files, some advantages of which are discussed here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With