|
Look at the assembly.
Sometimes, an extra variable changes what registry is selected or how the loop is constructed is more amenable to the CPU loop prediction. (I've seen counterintuitive results of code changes that boiled down to both.) You may also be seeing artifacts of load times. Larger code may cause segmentation.
(VC++ will optimize the loop out of existence. Thus any alleged differences in speed are errors in the benchmarking utility.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
I did a lot of performance analysis on different processors (mostly for embedded systems) including Intel's x86, but not AMD, and lots of C compilers.
My overall conclusion is there are a lot of factors some of which are difficult to control; one of them is code alignment (the address of the first instruction in a loop being at a multiple of 8 or 16 bytes).
Furthermore there is the issue of instruction scheduling: the CPU has different functional units, some in multiple quantities, and depending on minor details, the instructions get dispatched to some or other units, yielding better or worse performance. Adding an instruction may well lead to a faster piece of code.
The bigger issues however are inside the compiler itself; with standard optimization it should:
1. keep values in registers when there are very few involved (here only i and j);
2. figure out the loop does nothing useful and can be discarded;
3. if the net result of the loop would be some final value (i=UINT_MAX), then it should just assign that, but not in the current case since i and j are dead, their value is not used when the loop is done.
4. and for a real loop, with some body, it should consider "loop unroll".
So my advice is:
- start looking at the compiler switches, make sure you use a normal level of optimization (most of the time I apply several switches, the defaults aren't well chosen if you ask me);
- compare compilers for the kind of code that is most relevant to your app;
- only then start looking at the microscopic level. And get ready for a long learning curve.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello, I'm writing a MFC application to move a picture control when i press the "Next" button. (Please see screen-captures at following links)
http://i238.photobucket.com/albums/ff191/pumbaboy/before-move.jpg[^]
http://i238.photobucket.com/albums/ff191/pumbaboy/after-move.jpg[^]
There is a dialog box on which there are 2 picture controls. When I press the Next button, the left picture control should move on top of the right picture control.
You can see I kept the code for moving the picture control in a for loop because I wanted a sort of animation effect.
As you can see from the attachments, after I move the image there are some vertical lines appearing. How do I make them go away?
Thank you.
void CShabbirDlg::OnBnClickedButton2()
{
if (pageNum <= 10) {
pageNum++;
CRect RRect, LRect;
picPreview2.GetWindowRect(&RRect);
picPreview.GetWindowRect(&LRect);
for (long int i = LRect.left; i > RRect.left; i -= 20) {
picPreview.MoveWindow(i , LRect.top, LRect.Width(), LRect.Height());
}
}
}
|
|
|
|
|
we need 4 class for an sdi application why we need that application class ??and what is the program flow in a doc view program for an sdi appliction??
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
if u can't don't make any rubbish ..i hope u got it
|
|
|
|
|
Bisua wrote: if u can't don't make any rubbish ..i hope u got it
Well, this perfeclty applies to you also: if you can't make a valid question and do not bother reading the posting guidelines, don't make any rubbish post like you just did.
|
|
|
|
|
Bisua wrote: .i hope u got it
While you clearly haven't got it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Now guys, perhaps we should be nice and answer the questions...
Question 1
Bisua wrote: we need 4 class for an sdi application why we need that application class ??
Answer:
Guess WE really don't need it (you might) - there are many other ways to write a program (although you may have been told to use it).
Question 2
Bisua wrote: and what is the program flow in a doc view program for an sdi appliction??
Answer:
That all depends on how you write the program.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
You are not just an idiot, you also have a history of abusive behaviour towards people who actually want to help you but you're too stupid to realize that.
Go away and stop polluting this forum.
|
|
|
|
|
Genius!
|
|
|
|
|
Bisua wrote: we need 4 class
You are kidding right?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
I am trying to understand how to write an efficient OnPaint routine. That is, I want my routine
to only update the part of the screen that needs to be updated. Therefore I wrote a simple program
that creates a window and displays three lines. Below is the OnPaint routine for that program:
void<br />
CMainWindow::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
<br />
RECT rect1;<br />
BOOL retValue = GetUpdateRect( &rect1 );<br />
if ( retValue != 0 ) {<br />
char *ptr = 0;<br />
*ptr = 23;<br />
}<br />
dc.BitBlt( 0, 0, maxX, maxY, &m_memDC, 0, 0, SRCCOPY );<br />
}
The code works but the routine GetUpdateRect always returns 0. I am wondering if the only way to
get GetUpdateRect to return non-zero is if the program sends (via something like SendMessage)
the WM_PAINT message.
You should also observe that in the current code, if GetUpdateRect does return a non-zero value
then the program crashes. Currently, the program never crashes.
Bob
|
|
|
|
|
BobInNJ wrote: CPaintDC dc(this);
RECT rect1;
BOOL retValue = GetUpdateRect( &rect1 );
try the statement sequence in the following order:
RECT rect1;
BOOL retValue = GetUpdateRect( &rect1 );
CPaintDC dc(this);
Because, from documentation [^]:
BeginPaint automatically validates the update region, so any call to GetUpdateRect made immediately after the call to BeginPaint retrieves an empty update region.
(CPaintDC constructor eventually calls BeginPaint ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your response. I now understand what is going on.
Bob
|
|
|
|
|
I'm doing something very similar but in OnDraw() instead. GetUpdateRect() always returns an empty region. It's an SDI application. Any clues?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Since the CPaintDC is created in the view OnPaint method (that in turn calls OnDraw ), I think you've to override OnPaint , for instance:
void MyView::OnPaint()
{
GetUpdateRect(&m_rc);
CPaintDC dc(this);
OnPrepareDC(&dc);
OnDraw(&dc);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You can get the same info from dc.m_ps.rcPaint as well.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
Mike,
Thanks for the response. I noticed that the item you mentioned gives me exactly what I want
and therefore it is very useful. However, m_ps is a public data member of the class. Therefore,
I do not like the idea of using public data. Is using public data such a bad idea? I am not sure.
Bob
|
|
|
|
|
Hi gurus!
I coded an app that searches for another window to overlay it. I used SetLayeredWindowAttributes to make a color transparent in my window. When the the window with right handle was found i want to set place my window over it. For that i created a timer that runs every 10ms. To place my window over the other i used
::SetWindowPos(hndWin, hndOverlayWin, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
That works. But when hndWin (that one that should be overlayed) is in background of another window...and i click in hndwin it shortly flickers and the it's send back to background. But when i click a control in my overlaying transparent window the underlying window comes to front. But not if i click an area in the window that's overlayed.
The next thing is that the overlayed window is minimized and clicked in the taksbar, both windows should appear in front.
I'm happy if someone can help!!!
Thank you!
|
|
|
|
|
Has anybody experienced this?
I just installed IE 8 and Vista SP2. I'm supporting several VC++ 6.0 (MFC) projects and need to keep it alive on my system.
Now that these are installed, I can open workspaces and recent files, however if I select File-Open in Visual C++ I get nothing (no dialog). If I do it a couple more times VC++ crashes and closes. If I try using the toolbar or "Ctrl-O", VC++ crashes immediately.
Help!
- Mark
|
|
|
|
|
Mark,
I am thinking that the version of VC++ 6.0 that is installed on your machine was damaged or
altered by the installation of IE 8 or Vista SP2. This could be related to a new version of a DLL.
I would address this issue by reinstalling VC++ 6.0.
Bob
|
|
|
|
|
Mark C. Malburg wrote: I just installed IE 8 and Vista SP2. I'm supporting several VC++ 6.0 (MFC) projects and need to keep it alive on my system.
All the more reason not to mess with a stable system.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
True. I did get some significant improvement out of Outlook and the operating system in general. But I seem to be paying the price with my 11 year old IDE.
|
|
|
|
|
Perhaps MFC DLL hell?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|