Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35590
Seattle, WA USA
|
 |
« Reply #6 on: February 07, 2013, 07:28:16 pm » |
The only ways that seeking in a file is meaningful are if the file consists of fixed length records or the file has been scanned and key locations noted.
If every record is 80 characters, and the records are known to be in order, one could go to the start of the record in the middle of the file. The record of interest is either at that location, before it, or after it. One goes then to the middle of the half where the record must be, and looks again. Each seek/check operation cuts the range in half. Very quickly, the record of interest can be located.
If the file contains XML data, and the file has been scanned to locate all the tags of a given type, and the location of those tags recorded, one can then step through the file locating the records of interest. Suppose, for instance, that the XML file contains data about authors and the books they have written. If you scan the file, locating author tags, and created two lists, of authors and locations, you could present a list of authors, and, when one was selected, very quickly locate the area of the file where that author's books are stored.
The first pass through the file would not be all that quick, but subsequent uses of the file would be.
However, since OP hasn't defined how sh/she will determine the offset to seek to, we can only discuss possible reasons for what OP might want to do.
|