My program is very slow...WHY? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

My program is very slow...WHY?

Post by samggyy »

Hi there,

My program in the attachment is very slow when I just open a new "simulate" (Just open a new splitted window)...

Anyone would like to help please unzip my codes and try it please!

Another problem is: when I open a new splitted window and then I want to go back to original window just by using "End simulate". There is an error like 1.JPG shows below...

I really appreciate if you can help! Thanks a lot!!!
Last edited by samggyy on Mon Dec 15, 2008 5:00 pm, edited 1 time in total.
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

Several downloads without a reply...

My codes are nasty?? :twisted:
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

samggyy wrote:Several downloads without a reply...

My codes are nasty?? :twisted:
Guys...Please tell me your testing results!
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

i didn't compile the source, just had a quick look. Only thing i noticed is that you download the background image every time in your OnPaint event. This could be a reason for slowdown.

Other than that, i saw no processing code, just gui. So what exactly do you mean with "slow"?
Use the source, Luke!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Make it easier for us to help you, dumping your project and saying "it's slow, help me fix it" is not the best way. Do your homework and fix which parts are slow, then post there parts of relevant code with an explanation of what you want to achieve.
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

doublemax wrote:i didn't compile the source, just had a quick look. Only thing i noticed is that you download the background image every time in your OnPaint event. This could be a reason for slowdown.

Other than that, i saw no processing code, just gui. So what exactly do you mean with "slow"?
Thanks! Could you show me where I download the background image every time in the OnPaint event please? I did not notice that. How to fix it?

Yes, it is only a GUI but when I open it and new a profile the whole GUI works slowly. It shows the notebooks I created as following very slow. It seems it was generating the notebook and panel one by one...

Anyway, thanks a lot!

Code: Select all

// Initilize the original image notebook
	wxNotebook * pNotebook = new wxNotebook(pParent, eIdImageOriginal, wxDefaultPosition, wxSize(250, 300));

	wxPanel * pPanelOriginal = new wxPanel(pNotebook, eIdPanelImageOriginal);
	//pNotebook->AddPage(pPanelOriginal, wxT("Original Image"), true, iconIndex); //No Proper xpm icon image
	pNotebook->AddPage(pPanelOriginal, wxT("Original Image"), true);

	// Create PICM transform Panel
	wxPanel * pPanelRadonTransform = new wxPanel(pNotebook, eIdPanelRadonTransform);
	pNotebook->AddPage(pPanelRadonTransform, wxT("PICM Transform"), false);

	wxBoxSizer * pHoriImageOriginalNotebook=new wxBoxSizer(wxHORIZONTAL);
	pHoriImageOriginalNotebook->Add(pNotebook,0,wxALL,10);

	// Initilize the reconstructed image notebook
	wxNotebook * pReconNotebook = new wxNotebook(pParent, eIdImageRecon, wxDefaultPosition, wxSize(250, 300));

	wxPanel * pPanelRecon = new wxPanel(pReconNotebook, eIdPanelImageRecon);
	//pReconNotebook->AddPage(pPanelRecon, wxT("Transformed Image"), true, iconIndexRecon); //No Proper xpm icon image
	pReconNotebook->AddPage(pPanelRecon, wxT("Transformed Image"), true);

	wxBoxSizer * pHoriImageReconNotebook=new wxBoxSizer(wxHORIZONTAL);
	pHoriImageReconNotebook->Add(pReconNotebook,0,wxALL,10);
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

Auria wrote:Make it easier for us to help you, dumping your project and saying "it's slow, help me fix it" is not the best way. Do your homework and fix which parts are slow, then post there parts of relevant code with an explanation of what you want to achieve.
Sorry, I thought there are only a few lines :P

"It's slow" means the GUI can not paints the notebooks, panels, sub-windows smoothly. When I new a profile in my GUI the notebooks and etc seems to appear one by one. I don't know what's going on...

Thanks if any suggestion.
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Thanks! Could you show me where I download the background image every time in the OnPaint event please? I did not notice that. How to fix it?

Code: Select all

// Event for painting the background of the program UI
void 
WxReconSimerFrame::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);
	wxBitmap bitmapBackground(wxT("F:\\Programming Codes\\New Codes\\WxWidgetsTests\\WxReconSimer\\WxReconSimer\\resources\\Blurburger_008.png"), wxBITMAP_TYPE_PNG);
	dc.DrawBitmap(bitmapBackground, 0, 0, true);
}
Every time the window need a redraw, you load the image and display it. You should load the image once, e.g. in the frames ctor, store the pointer in a member variable and use that bitmap in the OnPaint handler.
Use the source, Luke!
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

doublemax wrote:
Thanks! Could you show me where I download the background image every time in the OnPaint event please? I did not notice that. How to fix it?

Code: Select all

// Event for painting the background of the program UI
void 
WxReconSimerFrame::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);
	wxBitmap bitmapBackground(wxT("F:\\Programming Codes\\New Codes\\WxWidgetsTests\\WxReconSimer\\WxReconSimer\\resources\\Blurburger_008.png"), wxBITMAP_TYPE_PNG);
	dc.DrawBitmap(bitmapBackground, 0, 0, true);
}
Every time the window need a redraw, you load the image and display it. You should load the image once, e.g. in the frames ctor, store the pointer in a member variable and use that bitmap in the OnPaint handler.
Sorry I do not understand...

Do you mean I put the part below in my wxFrame ctor?

Code: Select all

wxPaintDC dc(this);
wxBitmap bitmapBackground(wxT("F:\\Programming Codes\\New Codes\\WxWidgetsTests\\WxReconSimer\\WxReconSimer\\resources\\Blurburger_008.png"), wxBITMAP_TYPE_PNG);
dc.DrawBitmap(bitmapBackground, 0, 0, true);
However, what do you mean by "redraw" here? When I move the window it is not slow. I found it just slow when I new a profile. It generate panels one after the other...

Sorry about my explanation and I really appreciate your help!
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

i thought of something like this:

Code: Select all

WxReconSimerFrame::WxReconSimerFrame(...)
{
  // ... more code here

  // member variable: wxBitmap m_bitmapBackground
  m_bitmapBackground=wxBitmap(wxT("F:\\Programming Codes\\New Codes\\WxWidgetsTests\\WxReconSimer\\WxReconSimer\\resources\\Blurburger_008.png"), wxBITMAP_TYPE_PNG));
}

// Event for painting the background of the program UI
void
WxReconSimerFrame::OnPaint(wxPaintEvent& event)
{
  wxPaintDC dc(this);
  dc.DrawBitmap(m_bitmapBackground, 0, 0, true);
}
also, i didn't say this was the reason for the slowdown. I just said it *might* be a reason for a slowdown. Maybe the real reason is somewhere else, if you made the change, you'll know ;)

BTW: if you still get that assert message, maybe you should fix that first, this could have some bad side-effects. The message tells you exactly what the problem is.
Use the source, Luke!
samggyy
Experienced Solver
Experienced Solver
Posts: 95
Joined: Wed Aug 15, 2007 7:34 am
Location: London, UK/ China
Contact:

Post by samggyy »

Thanks! I have changed the codes and tested but it still slow to display the notebooks and panels. :cry:

I notice that when I new a profile. It will create a left panel and a right panel. The program create the left panel with notebooks on it at first. Then stop for 1 second and create the right panel above the left panel. Next, the right panel shows at the position of the left panel for 1 second. Then the right panel move to right place and left panel shows.

The whole procedure is not I expected because I want both left and right panels show at correct position simultaneously... not one after one... :oops:
Cheshire Cat will get Summa Cum Laude.

>>>>>>>>>>>>>>>>>>>>>>>>>>>
OS: Windows XP Pro & Linux 2.6.16
Compiler: MSVC++ 6/MSVS 2005 & linux-g++/KDevelop
wxWindows 2.8.7
Post Reply