none
Operate in Huge Files RRS feed

  • Question

  • Hi!

    Probably you know the Encylopedias Encarta, Britanica and Brockhaus.

     

    All of them have a sidebar with the list of all articles. If you click on an entry you INSTANTLY see the specific article.

     

    I have a binary file, full of articles as "binary saved strings" (with System.IO.BinaryWriter bw;   bw.Write((string)article);   )

     

    If I click on an Article(x) I have to open the file and have to call x-times bw.readString() untill I have the right article. But that's very slow. And the file is too large to load it into memory.

     

    Is there a way to directly access the specified article (x)?

    Monday, March 17, 2008 3:00 PM

Answers

  • You can seek to any location in the file by using Stream.Position = Value, or Stream.Seek(offset, SeekOrigin).
    However, you're going to have to establish some means of figuring out where in the file that you wish to seek.

    Perhaps open the file and read each entry individually, and create a dictionary of "article(x)"=>file location key/value pairs.
    Monday, March 17, 2008 4:17 PM

All replies

  • You can seek to any location in the file by using Stream.Position = Value, or Stream.Seek(offset, SeekOrigin).
    However, you're going to have to establish some means of figuring out where in the file that you wish to seek.

    Perhaps open the file and read each entry individually, and create a dictionary of "article(x)"=>file location key/value pairs.
    Monday, March 17, 2008 4:17 PM
  • Hi

    You can maintain a dictionary of article offset and the size of article.
    So before you write the article to file, you will create a dictionary which would contain the Article ID, the offset and the size of article and save the dictionary seperatly.

    When you need to access any article, you can use the BinaryReader.Read Method to read the specified article by gathering the offset and the size from the dictionary.


    Thanks n Regards
    Anu Viswan
    Tuesday, March 18, 2008 11:10 AM