|
Since you have a thread to show the video, timer is not needed. You can use Sleep API in the loop. But the problem is that it cannot give you a much precision. You have to play the video on by looking at the time (I think GetTickCount is useful) instead of using sleep for a real time video show.
- NS -
|
|
|
|
|
For the display of the video should use the main MFC thread (your app). So use the normal OnTimer() handling.
For standard use I create a main MFC app, and for special use a "worker" thread for communicating with devices or greater mathematical operations.
Greetings from Germany
|
|
|
|
|
I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications. Why I have this doubt is because my application is utilizing full 100% of CPU all the time. My application has one serial port reading thread which should take only very little CPU another a fully mathematical thread and third a display thread.
|
|
|
|
|
The high CPU utilization is very bad. It is in best case a missdesign in worst a bug.
Identify and eliminate this via Sleep(), a Timer or Waiting for a Event.
Greetings from Germany
|
|
|
|
|
jossion wrote: I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications.
With MFC, you should be using AfxBeginThread() .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
jossion wrote: Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job.
You probably shouldn't, since the primary thread owns the UI. Instead, have the secondary thread post a message to the primary thread indicating what needs to be displayed.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi friends,
I have developed a software involving sockets-parsing-database transfer. I can connect upto 6 machines to this software(s/w). These machines send out data on TCP/IP. Thus on s/w's end i have six OnReceive() events(Please note that so far there is no mention of threads)
There are 2 types of string that these machines can send to the s/w: transaction string and the other one is batch-string. Upon receiveing a batch-string the s/w assigns a batch number to all previous transaction strings and then transfers these strings to MS SQL database(DB). E.g. i take 5 transactions then generate a batch-string thus the DB will contain 5 rows with batch no. provided by the batch string i.e. batch string is used only to assign a 'batch no.'. While the transactions are being taken the data is stored in a CString array.
Apart from this the s/w sends an 'OK' display message to the machine if a string is received. This OK message is cleared only at the end of 'parsing function'(OnReceive->Parsing->Store in variables->Send OK->Transfer to DB if batch-string->Wait for 3 secs and Clear OK[seperate thread]).
Now the question is there are cases where in a valid string is getting missed/not captured by the s/w. Note that valid strings are transmitted out only once and there is no handshake. Also there are cases where in an OK message is displayed but still some row goes missing in the DB.
What are problem areas in this? How can i make this s/w more efficient??
P.S: Kindly let me know if more data is needed
|
|
|
|
|
I'd say this is too much information.
It's hard to tell how to help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Am doing a little code review...
Is it safe to delete a CWnd derived object immediately following a call to CWnd::DestroyWindow on it?
I would assume yet -- but if not, when is it safe to do so?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
See CWnd::PostNcDestroy()
- NS -
|
|
|
|
|
|
Actually I meant the same that CFrameWnd do.
void CFrameWnd::PostNcDestroy()
{
delete this;
}
- NS -
|
|
|
|
|
But you told him to check the CWnd::PostNcDestroy()
|
|
|
|
|
Ofcourse. MSDN clearly says "Derived classes can use this function for custom cleanup such as the deletion of the this pointer." in Remarks section. Please have a look.
- NS -
|
|
|
|
|
Thats ok. After checking that function in MSDN, he will understand that he can delete this pointer from the postncdestroy() function. But his question was whether its safe to delete a CWnd pointer and the above explanation doesnt answer it. Like if it is not safe, why?
|
|
|
|
|
His question is a little bit different. He asked whether it can be done from DestroyWindow. But PostNCDestroy is called from void CWnd::OnNcDestroy() which is called when WM_NCDESTROY is sent to that window. WM_NCDESTROY is the last message received by the window in destruction. So I think it is safe to use, if it is safely handled. I mentioned that CFrameWnd is using this technique safely.
- NS -
|
|
|
|
|
One thing I find inside the Destroy -- is a call to Detach -- which seperates the HWND from the CWnd. It seems safe to delete at that time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
assumption:
char c[4]={1,2,3,4};
char* addr=c;
then addr is the address of c[0], the address c is the address c[0];then i want to know, what is the mean and value of &c? what is the mean of (int*)&c ?
thanks
|
|
|
|
|
It is pointer to pointer i.e. int**
|
|
|
|
|
Lao Wang wrote: what is the mean and value of &c?
It is the address of c array. It will be same as &c[0].
Lao Wang wrote: what is the mean of (int*)&c ?
It is only a conversion of pointer from (char*) to (int*)
- NS -
|
|
|
|
|
NS17 wrote: It is only a conversion of pointer from (char*) to (int*)
char* ? or char** ?
|
|
|
|
|
Yes char** is correct.
I mentioned only about the memory adresss.
- NS -
|
|
|
|
|
you already got some good answers, but i'll sum it up.
c is defined as an array of char , so, basically, it can be seen as a char* .
& used as an unary operator means to return the address of the variable attached, so &c is the address of c.
but as c is a char* , its address is a char** .
in front of it, you have a cast operator, which casts the address returned into an int* address
|
|
|
|
|
thanks
as your mean, &c=char** , but the equation char ** c=&c, has compile wrong message with "can not convert from char (*)[4] to char **"
so i think &c != &c[0];
|
|
|
|
|
Lao Wang wrote: so i think &c != &c[0];
how do you test this ?
BTW, c == &(c[0])
but the first element of the array is at the address of the beginning of the array
|
|
|
|