CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Posts
    12

    Huge files problem

    I am working on an app that should open a logfile and then it should be possible to:

    1. output the whole file as it is
    2. reverse the output
    3. filter the output

    I am outputting to a richtextbox since I also want to highlight specific lines.

    I have tried both using ArrayList and StringBuilder. The latter seems better but then it is not so easy to reverse. To add all text to the RichTextBox I use RTB.Text. I have also thought of outputting all to a temp file and use RTB.LoadFile instead.

    The problem is that the logfiles can be quite huge, >5MB in extreme cases. This causes it to be very slow and I also encounter out-of-index problems in certain situations that I have not been able to pin down in the debugger.

    Could anyone advice me on the best way to get a stable and not to slow solution (since I have to work through the whole file line by line to filter it will never be quick)?

  2. #2
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: Huge files problem

    I cant get where you have this problem exactly,although I dont know how you load this huge file,

    I think if you use stream and streamreader it would be better ...

    if I'm wrong please notice me,
    any better opinions for such situations??

    ---------------
    Mehdi.

  3. #3
    Join Date
    Jun 2004
    Posts
    12

    Re: Huge files problem

    Sorry about that, should have been more informative I guess. The code looks like this (You can see both approaches, the arraylist and stringbuilder):


    try
    {
    StreamReader sr = File.OpenText(fileName);
    string input = null;
    //ArrayList myList = new ArrayList();
    StringBuilder sb = new StringBuilder();

    while ((input = sr.ReadLine()) != null)
    {
    if ( Filter or not )
    {
    Filtering of each line. If condition met then
    sb.Append(input);
    //myList.Add(input);
    }
    else {
    sb.Append(input);
    //myList.Add(input);
    //myList.TrimToSize();
    }

    }
    sr.Close();
    //myList.TrimToSize();
    if ( checkBox4.Checked ) { //myList.Reverse(); }
    richTextBox1.Clear();

    /*
    for (int i=0;i<myList.Count;i++)
    {
    sb.Append(myList[i].ToString() + "\n");
    }
    */
    richTextBox1.Text = sb.ToString();

    }
    catch (Exception e)
    { MessageBox.Show(e.ToString()); }
    }

    It seems as the StringBuilder solution is better but I don't know how to reverse in a nice way, since the java stringbuilder.reverse does not seem to exist in C#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured