Search code examples
c++wxwidgets

WxTextCtrl unable to load large texts


I've read about the solutuon written here on a post a year ago wx.TextCtrl.LoadFile()

Now I have a windows application that will generate color frequency statistics that are saved in 3D arrays. Here is a part of my code as you will see on the code below the printing of the statistics is dependent on a slider which specifies the threshold.

void Project1Frm::WxButton2Click(wxCommandEvent& event) {

char stat[32] ="";
int ***report = pGLCanvas->GetPixel();
float max = pGLCanvas->GetMaxval();
float dist = WxSlider5->GetValue();
WxRichTextCtrl1->Clear();
WxRichTextCtrl1->SetMaxLength(100);
if(dist>0)
{    
    WxRichTextCtrl1->AppendText(wxT("Statistics\nR\tG\tB\t\n"));
     for(int m=0; m<256; m++){
         for(int n=0; n<256; n++){
              for(int o=0; o<256; o++){

                        if((report[m][n][o]/max)>=(dist/100.0)) 
                        {
                            sprintf(stat,"%d\t%d\t%d\t%3.6f%%\n",m,n,o,report[m][n][o]/max*100.0);
                            WxRichTextCtrl1->AppendText(wxT(stat));
                        }

                   }
              }     
         }     
}
else if(dist==0) WxRichTextCtrl1->LoadFile("histodata.txt");

}

The solution I've tried so far is that when I am to print all the statistics I'll get it from a text file rather than going through the 3D array... I would like to ask if the Python implementation of the segmenting can be ported to C++ or are there better ways to deal with this problem. Thank you.

EDIT: Another reason why I used a text file instead is that I observed that whenever I do sprintf only [with the line WxRichTextCtrl1->AppendText(wxT(stat)); was commented out] the computer starts to slow down.

-Ric


Solution

  • Disclaimer: My answer is more of an alternative than a solution.

    I don't believe that there's any situation in which a user of this application is going to find it useful to have a scrolled text window containing ~16 million lines of numbers. It would be impossible to scroll to one specific location in the list that the user might need to see easily. This is all assuming that every single number you output here has some significance to the user of course (you are showing them on the screen for a reason). Providing the user with controls to look up specific, fixed (reasonable) ranges of those numbers would be a better solution, not only in regards to a better user experience, but also in helping to resolve your issue here.

    On the other hand, if you still insist on one single window containing all 64 million numbers, you seem to have a very rigid data structure here, which means you can (and should) take advantage of using a virtual grid control (wxGrid), which is intended to work smoothly even with incredibly large data sets like this. The user will likely find this control easier to read and find the section of data they are looking for.