|
Hi,
OS? probably not really multitasking and hanging in another process.
Sytem clean up?
Kind of magic numbers?
Swapfile operations?
GSte
|
|
|
|
|
Thanks for the reply.
Sorry, you're right, I should have included more information.
I'm running on Windows 2000, and probably working this machine a little too hard with quite a few processes.
As to the rest of you reply, I'm not really sure what information you're asking for? If you could, it'd be great if you could go into a little more detail as to exactly what information is relevent. It would be even GREATER if you could give me a little advice on how to collect it.
Jeez, I don't ask for much, do I?!
Thanks again,
Pete
|
|
|
|
|
Hi,
Sorry that I didn't make it clear. Those were not questions but hints, what you should ask.
Like, are there page misses, so the system as to relad memory from the swapfile.
Is any process eating up CPU-time by atomic instructions (anti virus software/ multimedia player).
If your using W2000 try to shut down most processes you can, to get the time measurement more reliable.
See if there is a pattern in the time frame, like every third or fourth call is aout of order.
I can't give you a solution, but just a few hints how to track the problem.
And if anything fails, use your imagination.
I once had a similiar problem and a wrongly installed outlook proofed to be the trouble maker.
Regards
GSte
-- Even dwarves were born small --
|
|
|
|
|
Hi GSte,
Thanks again for your input on this, I really appreciate it!
Would you be able to point me in the right direction on how I can look into the page-misses stuff? Is this something I can investigate with in-code profiling, or with the Task Manager, or do I need some more specialized profiling tools?
Also, after some more experimentation (including turning off my internet radio - doh!), I've found the following:
- Minimizing the number of other processes seems to have negligable effect.
- The slow calls only happen when the window size is being /increased/, never when it is being /decreased/.
- If I resize the window slowly, then every other BitBlt() call is slow, e.g.:
<-----------------SNIP-------------------->
...
...
C2DTrajWindow::UpdateVirt(): m_memDC.BitBlt( 0, 0, 1280, 752, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 0.011454 milliseconds
C2DTrajWindow::UpdateVirt(): m_memDC.BitBlt( 0, 0, 1280, 755, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 630.962036 milliseconds
C2DTrajWindow::UpdateVirt(): m_memDC.BitBlt( 0, 0, 1280, 758, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 0.015086 milliseconds
C2DTrajWindow::UpdateVirt(): m_memDC.BitBlt( 0, 0, 1280, 762, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 636.752995 milliseconds
...
...
etc.
<-----------------SNIP-------------------->
I don't suppose you have any insights after seeing this information?
Thanks again,
Pete
|
|
|
|
|
hi again,
Looks like we found the nasty guy. Page misses.
Everytime you make the picture larger a new block of memory must be allocated. If the RAM is low, than a part of the memory must be swapped to the memory file on disk (aka swap file). And that's what takes so long. Only solution so far ( And I mean this serene) lots of RAM, RAM, RAM.
How can I tell?
You see, the first allocation gets swift. When you increase the picture size, the system will allocate a block of memory a liitle bit larger than needed. That makes the second enlargement pretty fast. The third enlargement must be reallocated again (slow). And so forth.
Probably (I don't know for sure) you can preallocate a reasonable (lets say 1600*1200) amount of memory prior BitBlitting the immage the first time. That way by enlargening a smaller picture needn't to be reallocated until it exceeds the size of 1600*1200. But I don't know how this could be done.
Maybe a code like this will work.
Avoid flickering
-- Disable Output
BitBlitt(1600*1200)
Enable Output
BitBlitt(1280*600)
BitBlitt(1280*610)
and so on.
How to en/disable painting the image depends. There are several functions for this purpose.
Regards. Please referr to you most likely base class reference.
Regards
GSte
GSte
|
|
|
|
|
I follow your reasoning, and it does seem completely reasonable.
The only thing is, I don't see why BitBlt() is /allocating/ memory. As far as I was aware, BitBlt only copies blocks of memory.
I /am/ allocating larger bitmaps as the window size increases, but that's done outside of the code I'm profiling. Here's how I'm profiling the code:
<------------------SNIP---------------------->
#ifdef _DEBUG
LARGE_INTEGER time4;
VERIFY( ::QueryPerformanceCounter( &time4 ) );
#endif
m_memDC.BitBlt( 0, 0, m_iScreenWidth, clientRect.Height(), &m_decorationsMemDC, 0, 0, SRCAND );
#ifdef _DEBUG
LARGE_INTEGER time5;
VERIFY( ::QueryPerformanceCounter( &time5 ) );
#endif
...
...
...
TRACE( " m_memDC.BitBlt( 0, 0, %i, %i, &m_decorationsMemDC, 0, 0, SRCAND ) ] took %f\tmilliseconds\n"
, m_iScreenWidth, clientRect.Height(), ((time5.QuadPart - time4.QuadPart)/(double)freq.QuadPart)*1000 );
<------------------SNIP---------------------->
As you can see, the only thing I'm timing is that one call to BitBlt(...), so it's definitely something within that method that's slowing down.
One thought I had was that maybe BitBlt() is doing some behind-the-scenes allocation for some reason? Or perhaps there's some lazy-initialization going on where the CBitmaps attached to my CDCs only allocate memory when needed, in this case somewhere within BitBlt(). That doesn't really make sense though - I'm drawing into the source CDC before the guilty BitBlt() call (and presumably the memory would have to be allocated then), and I call
m_memDC.BitBlt( 0, 0, m_iScreenWidth,
clientRect.Height(), NULL, 0, 0, WHITENESS );
earlier as well, so as far as I can tell both the source and destination DCs' CBitmaps should already be allocated when that slow call BitBlt() happens.
Strange, no? Anyways, thanks once again for your help. If you have any further thoughts, obviously I'd love to hear them!
Cheers,
Pete
|
|
|
|
|
What is the value for rcClipBox if you call
CRect rcClipBox;
m_memDC.GetClipBox(rcClipBox);
TRACE("l: %d, t: %d, r: %d, b: %d",
rcClipBox.left, rcClipBox.top,
rcClipBox.right, rcClipBox.bottom);
just prior to each BitBlt call?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
C2DTrajWindow::UpdateVirt:
ClipBox - l: 0, t: 0, r: 1280, b: 740
m_memDC.BitBlt( 0, 0, 1280, 740, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 617.089323 milliseconds
C2DTrajWindow::UpdateVirt:
ClipBox - l: 0, t: 0, r: 1280, b: 748
m_memDC.BitBlt( 0, 0, 1280, 748, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 1.938794 milliseconds
C2DTrajWindow::UpdateVirt:
ClipBox - l: 0, t: 0, r: 1280, b: 750
m_memDC.BitBlt( 0, 0, 1280, 750, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 628.530162 milliseconds
C2DTrajWindow::UpdateVirt:
ClipBox - l: 0, t: 0, r: 1280, b: 760
m_memDC.BitBlt( 0, 0, 1280, 760, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 1.418616 milliseconds
|
|
|
|
|
OK, how about the clipbox values for m_decorationsMemDC?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Hi Jack,
Pretty much the same story:
<---------------------SNIP----------------------->
C2DTrajWindow::UpdateVirt:
m_memDC's ClipBox - l: 0, t: 0, r: 1280, b: 807
m_decorationsMemDC's ClipBox - l: 0, t: 0, r: 1280, b: 807
m_memDC.BitBlt( 0, 0, 1280, 807, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 684.505154 milliseconds
C2DTrajWindow::UpdateVirt:
m_memDC's ClipBox - l: 0, t: 0, r: 1280, b: 809
m_decorationsMemDC's ClipBox - l: 0, t: 0, r: 1280, b: 809
m_memDC.BitBlt( 0, 0, 1280, 809, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 2.769346 milliseconds
C2DTrajWindow::UpdateVirt:
m_memDC's ClipBox - l: 0, t: 0, r: 1280, b: 812
m_decorationsMemDC's ClipBox - l: 0, t: 0, r: 1280, b: 812
m_memDC.BitBlt( 0, 0, 1280, 812, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 683.831325 milliseconds
C2DTrajWindow::UpdateVirt:
m_memDC's ClipBox - l: 0, t: 0, r: 1280, b: 815
m_decorationsMemDC's ClipBox - l: 0, t: 0, r: 1280, b: 815
m_memDC.BitBlt( 0, 0, 1280, 815, &m_decorationsMemDC, 0, 0, SRCAND ) ] took 2.098870 milliseconds
<---------------------SNIP----------------------->
Cheers,
Pete
|
|
|
|
|
<ctrl><alt> Have you ever look at how many processes might be running on you machine at one time. BitBlt() is like every other piece of code running on youre machine, it is a matter of priority (every body gets a slice of the processors time [at least they are supposed to]). I discover a virus once, becuase I notice that processor time was being eatin (slow down in resonse time).
May be someone can give you an idea for improving the speed if you explained why the graph is rendered in pieces, instead of as a whole.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
hai..
I'm working on win32 vc++..I want to know waht is the window message that is processed when the window is maximized and minimized..
thanks.
|
|
|
|
|
Look at WM_SIZE.
wParam = SIZE_MAXIMIZED, SIZE_MINIMIZED, SIZE_RESTORED, etc.
lParam = cx -> lo word cy -> hi word
Hope this helps.
|
|
|
|
|
Is thera any way for
int a = 5;
int b;
b's memory address point to a's?
so &b would equal to &a.
Or the only way is create a pointer to do it
int a = 5;
int *b;
b = &a;
|
|
|
|
|
Or the only way is create a pointer to do it
me think yes.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Isn't a pointer just a long integer anyways? I didn't try this, but I don't see a reason why a long int couldn't hold an address...it doesn't care if it's an address...as long as it is a value which matches its type.
I don't know why you'd do this though...that's what pointers are for...
|
|
|
|
|
This will break 64 bit code (AMD64) where pointers are 64 bits and integers are 32 bits.
John
|
|
|
|
|
I believe you could use references for this:
int a = 5;
int &b = a;
a = 500; //now a == 500 AND b == 500
b = 1234; //now a == 1234 AND b == 1234
I'm not totally sure that's right though, you should probably step through the code in a debugger and check.
Hope that helps,
Pete
|
|
|
|
|
I stand corrected, forgot about references.
int a = 5;
int &b = a;
in that case, &a == &b ( the address of a and b are the same).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thanks. I totally forgot about that one
How would I go about so b's memory address would point to a's memory address?
class CFirst(){
private:
int a;
public:
CFirst(){ a = 25; };
int ReturnA(){ return(a); };
};
class CSecond(){
private
int b;
};
int main(){
CFirst a;
return 0;
}
The stuff I am doing is a little bit more complex. I want to point b's link list data to a's link list's data and then remove the la ink list(without destroying the data)
|
|
|
|
|
You know, you really should join up and sign in if you want people to help you out Membership is the key...
Anyway, something along these lines might point you in the right direction:
class CFirst
{
...
...
public:
int &GetReferenceToA()
{ return a; }
...
...
}
class CSecond
{
public:
class CSecond( int &numberToAttachTo )
: b( numberToAttachTo )
{}
protected:
int &b;
};
int main()
{
CFirst instanceOfFirst;
CSecond instanceOfSecond( instanceOfFirst.GetReferenceToA() );
...
...
}
I don't know how much that helps. There would be quite a few ways of initializing the 'connection' between a and b.
One thing to note is that any member variables of CSecond() that are references MUST be initailized at construction time. This makes them more fiddly to use than pointers, IMHO.
HTH,
Pete
|
|
|
|
|
The stuff I am doing is a little bit more complex. I want to point b's link list data to a's link list's data and then remove the la ink list(without destroying the data)
you can't really do that, at least the way I think you want to do it.
if your data ( a or b ) are not dynamically allocated ( new or malloc ) , then, you will need to copy the data; and passing a reference a to b and then removing a will invalidate b ( at best ).
in your example, ReturnA copies the data.
but for example, if your CFirst looks like :
class CFirst {
int* a; // will be allocated and assigned.
int* ReturnA( return a;};
}
then, you return the address of a to whoever receives it;
int* b = ReturnA();
but you will need to keep track of allocation and deallocation.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I have an account I just keep forgetting to log in.
int* ReturnA(){ return a;};
doesn't work.
I have been trying to get function to return pointer
Nevermind I am an idiot. Forgot to add () when I call the function
You can't assign &b on the fly right? Only at the intitalization.
|
|
|
|
|
You could create a 'reference'. A reference variable is somewhat like a mix between a pointer and a copy variable. References are much like synonymes with same type.
For example:
int A = 5;
int& B = A; Now both &A and &B operations return the same value, A's address. If A is changed, B changes, and vice versa. In syntactical terms, however, they are the same thing. Same thing (an integer variable) with two seperate names.
-Antti Keskinen
----------------------------------------------
"If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?"
-- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.
|
|
|
|
|
I only saw part of the other answers! But...
-----------------------------------------------------------------------------
int A = 5; // declared and intialized
int *pB = &A; // ponter to int declared and intialized to address of A
// pB is an inderect reference to A, which means it holds the address of A
// &A is the address of A (aka. indirect reference)
// *pB is a dereferncenced pointer (aka. direct reference)
int &C = A; // direct reference declared and intialized
// C and A are both references to the same data (memory location)
// Therefor, &A = pB = &C and A = *pB = C.
-----------------------------------------------------------------------------
Thats it, in a nut shell.
-----------------------------------------------------------------------------
It seems complicated, don't it. Given time it will become second nature to you.
-----------------------------------------------------------------------------
This might help:
#include <stdio.h>
int main(void)
{
int A = 5;
int *pB = &A;
int &rC = A;
prinf(
"Address of A = %p, Value of A = %d\n"
"Address of pB = %p, Address stored in pB = %p, Value of *pB = %d\n"
"Address of rC = %p, Value of rC = %d\n",
&A, A,
&pB, pB, *pB,
&rC, rC);
return 0;
}
I have not tested the code above, but is should give you an idea of the relationships between pointers and references.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|