views:

544

answers:

1

Hello,

I'm having a problem with storing amazing amounts of text in a rich TextBox.

I'm trying to read a text file fairly big( anywhere from 90mb to 450mb), and put what I've read in a rich textbox. It works in a simple program, but when I do in a complicated program I get an OutOfMemory exception.

One thing to note is that when I exit my simple program, I get an OutOfMemory exception right before the program returns 0.

Here is my simple program's code:

    array<String^>^ strArray;
    StreamReader^ sr;
    String^ dummyStr;
    int dummyInt;

        sr = gcnew StreamReader("C:\\testsize.txt");

        while( (dummyStr = sr->ReadLine() )!= nullptr)
        {
            dummyInt++;
        }
        sr->Close();

        sr = gcnew StreamReader("C:\\testsize.txt");
        strArray = gcnew array<String^>( dummyInt );
        for(int i=0; i < strArray->Length; i++)
        {
            strArray[i] = sr->ReadLine();
        }
        richTextBox1->Lines = strArray;

I have a similar snippet of code in my project, and the exception pops up when I do the richTextBox1->Lines = strArray line.

I have read the documentation of the rich textbox, and it says the max limit is 64KB worth of characters, but that makes sense halfway through, as I can load the text, but I guess the program has a problem dumping it afterwards.

Any ideas? I have been trying to find maybe some custom controls without a limit, but to no success so far.

+1  A: 

As far as dumping a huge amount of text into a rich edit, this usually is going to be excruciatingly slow, take notepad for example, try and open a 2MB file with it. I think the way more advanced text editors deal with these is by a 'virtual control' I know these are often used with list controls, and I would think with text boxes as well. They basically act/function the same way as your normal everyday control but without trying to render oodles of text at a time, they have virtual space 'off the screen space'.

As far as your out of memory issue... I'm confused you say the error happens at the last line of your sample code when you try and dump your text to it. You also mention that the limit is 64KB so now assuming your file is huge like you say... it makes sense you get an error there you've tried to dump more than 64KB text into a 64KB limited box. Am I missing something?

Edit I reread some of the question I see what you are asking now, so in the simple program you get an error after everything is loaded done, when the program exits. Throw a debug point into your destructors, and see exactly where this error happens.

Edit 2 Now that I know what system you are on, I went and had a look, the documentation is a little more complex than 64K limit. Which first of all isn't referring to 64 KB but rather 64000 characters. Also note that you can change this limit as you please. Secondly if you are streaming with SF_TEXT and not SF_RTF this limit has no effect, which I would imagine is what is going on behind the seen of the .NET interface.

DeusAduro
On the memory issue,I mentioned it because in the simple program I am able to load code (even if slow) and then scroll through it and everything. I get the exception when I try to close the program(right before the "return 0;" statement). In the more complex project I get the exception when I try to load the code. I was trying to point out that it is possible to load 90mb worth of code in the 64KB textbox, thats why I was boggled haha.
Dinoo
Ya sorry I caught that on the second read through. And it seems pretty odd... what platform/api are you using?
DeusAduro
No prob. Its under Vista, VS 2008, C++. So I guess .NET?
Dinoo
I have 39 thousand lines in my sample file, each with anywhere from 10 to 30 characters per line, so I still beat that limit by a mile haha. I tried looking more into the destructor as you suggested, but cannot see anything out of the ordinary. One thing I did note is that both the rtf and Text properties have an OutOfMemory exception in their value fields when debugging. And my textLenght is at...92million. I am guessing I have to find some control that does what you suggested in your first paragraph, and hopefully dont have to do it myself haha. Thanks for the help
Dinoo