|
Hi,
Im OnTImer(), i use the values stored in structure ,but when timer is on..it shows correct value but i invoke another timer in dialog,after sometime,,,First timer gets wrong value from structure. How its possible..THis is my code..
STRIG CirTab[] = { // circle sin, cos, table
{ 0, -7999 },
{ 836, -7956 },
{ 1663, -7825 },
{ 2472, -7608 },
{ 3253, -7308 },
{ 3999, -6928 },
{ 4702, -6472 },
{ 5353, -5945 },
{ 5945, -5353 },
{ 6472, -4702 },
{ 6928, -4000 },
{ 7308, -3253 },
{ 7608, -2472 },
{ 7825, -1663 },
{ 7956, -836 }
};
OnTImer code has
LineTo(hDC, clockCenter.x + (INT)(((LONG)(CirTab[pos].sin) * (radius)) / CLKSCALE),
clockCenter.y + (INT)(((LONG)(CirTab[pos].cos) * (radius)) / CLKSCALE));
THe bolded varaible get correct value until the second timer (Dialog timer) getinvoked .Here 'pos' is seconds in time.
At First second it get value of { 0,-7999 } but second timer inviked after some time it shows then values as {12245,23452) but its not present in CirTab[].
Whats the reason??Pls..any suggestion??
Anu
|
|
|
|
|
Anu_Bala wrote:
LineTo(hDC, clockCenter.x + (INT)(((LONG)(CirTab[pos].sin) * (radius)) / CLKSCALE),
clockCenter.y + (INT)(((LONG)(CirTab[pos].cos) * (radius)) / CLKSCALE));
Anu_Bala wrote: Here 'pos' is seconds in time.
So you are accessing the array by using pos which is in seconds. But in the array you have less than 15 members and if the seconds go beyond 15 it will access from outside array which gives you a junk value thats not present in array. In summery you're accessing out of array.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
modified on Tuesday, June 17, 2008 1:04 AM
|
|
|
|
|
Actually my array contains 60 members.For here just i post only 15members for your reference.Sorry for thsi confusion.
Anu
|
|
|
|
|
1) Could you check whether the pos goes out of index?
2) Check whether your array values are getting updated by some bad code. Watch the array when you've the error.
Could you post the code snippet?
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
No, pos shows only between 1 and 60 only.
Arrays doesnot get changed and also the array is not used in sometoher place, used only in this line.
My code is to draw seconds needle in clock image.
DrwaHnad function is called in OnTimer()
DrawHand(register HDC hDC,INT pos,HPEN hPen,INT scale,INT patMode)
{
INT radius;
MoveToEx(hDC, clockCenter.x, clockCenter.y, NULL);
radius = (INT)(((LONG)clockRadius * scale) / 200);
SetROP2(hDC, patMode);
SelectObject(hDC, hPen);
LineTo(hDC, clockCenter.x + (INT)(((LONG)(CirTab[pos].sin) * (radius)) / CLKSCALE),
clockCenter.y + (INT)(((LONG)(CirTab[pos].cos) * (radius)) / CLKSCALE));
}
Array is..
STRIG CirTab[] = { // circle sin, cos, table
{ 0, -7999 },
{ 836, -7956 },
{ 1663, -7825 },
{ 2472, -7608 },
{ 3253, -7308 },
{ 3999, -6928 },
{ 4702, -6472 },
{ 5353, -5945 },
{ 5945, -5353 },
{ 6472, -4702 },
{ 6928, -4000 },
{ 7308, -3253 },
{ 7608, -2472 },
{ 7825, -1663 },
{ 7956, -836 },
{ 8000, 0 },
{ 7956, 836 },
{ 7825, 1663 },
{ 7608, 2472 },
{ 7308, 3253 },
{ 6928, 4000 },
{ 6472, 4702 },
{ 5945, 5353 },
{ 5353, 5945 },
{ 4702, 6472 },
{ 3999, 6928 },
{ 3253, 7308 },
{ 2472, 7608 },
{ 1663, 7825 },
{ 836, 7956 },
{ 0, 7999 },
{ -836, 7956 },
{ -1663, 7825 },
{ -2472, 7608 },
{ -3253, 7308 },
{ -4000, 6928 },
{ -4702, 6472 },
{ -5353, 5945 },
{ -5945, 5353 },
{ -6472, 4702 },
{ -6928, 3999 },
{ -7308, 3253 },
{ -7608, 2472 },
{ -7825, 1663 },
{ -7956, 836 },
{ -7999, -0 },
{ -7956, -836 },
{ -7825, -1663 },
{ -7608, -2472 },
{ -7308, -3253 },
{ -6928, -4000 },
{ -6472, -4702 },
{ -5945, -5353 },
{ -5353, -5945 },
{ -4702, -6472 },
{ -3999, -6928 },
{ -3253, -7308 },
{ -2472, -7608 },
{ -1663, -7825 },
{ -836 , -7956 }
};
Anu
|
|
|
|
|
Anu_Bala wrote: No, pos shows only between 1 and 60 only.
Array index starts from zero. Your pos is zero based index?
NB: While posting code, embed them in code block for better readability.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Initially i declared pos =0;
One question regarding forum:
In last answer u get one line from my post and asked question for that(grey line ).How u get that??
Anu
|
|
|
|
|
Anu_Bala wrote: Initially i declared pos =0;
Initially its working also. Did you checked whether the index go beyond 59 when you get bogus values?
Anu_Bala wrote: One question regarding forum:
In last answer u get one line from my post and asked question for that(grey line ).How u get that??
While writing reply, The previous message will be displayed above in blue color. Select the lines you want to quote and click "Quote Selected Text" button.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: Initially its working also. Did you checked whether the index go beyond 59 when you get bogus values?
No the index showing values between 0 and 59 only. Only the array value is getting changed.
Im just confused .How it happens like this.
If i didnot invoke second timer(dialog class),the clock shows the correct needle position.No problem occurs.
But when i invoked this dialog timer ,after 55 seconds invoked of second timer..The needle get distorted.When i debug,i found that array values is getchanged.
In second timer(dialog class) i code like this
void CReplay::OnTimer(UINT nIDEvent)
{
CListCtrl *pCtrl = (CListCtrl*)GetDlgItem(IDC_REPLAYLIST);
char ListBoxStr[50];
CString now;
CTime time;
static int j=1;
int index = 0;
pCtrl->DeleteAllItems();
for(int i=0;i<nosize;i++)
{
sprintf(ListBoxStr,"%d",i+1);
pCtrl->InsertItem(i,(CString)ListBoxStr);
sprintf(ListBoxStr,"%s",rptime[i]);
pCtrl->SetItemText(i,1,(CString)ListBoxStr);
}
pCtrl->SendMessage(WM_VSCROLL,MAKELPARAM(SB_BOTTOM,0),NULL);
CDialog::OnTimer(nIDEvent);
}
Anu
|
|
|
|
|
Anu_Bala wrote: When i debug,i found that array values is getchanged.
Make your array const. Then probably during compilation itself you can find the part which modifies the array.
const STRIG CirTab[] = {
BTW, you're using this array for getting the sin and cos values. right? why can't you get it by calling sin() and cos() . Does that cause a huge performance overhead?
Well, whats the signature of STRIG struct? Is member datatypes are sufficient to hold the values? If they are not enough, you'll get bogus values.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: whats the signature of STRIG struct? Is member datatypes are sufficient to hold the values?
typedef struct
{
SHORT sin;
SHORT cos;
} STRIG;
This is my structure definition
Anu
|
|
|
|
|
Short is enough to hold you're values. Did you change that array to const ? So that the values cannot be modified. Just try.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Yes I got it...
I put const for array.
its working..
Thank you so much.
Thanks
Anu
|
|
|
|
|
Anu_Bala wrote: its working..
Wow!!! Its party time.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
You are welcome. Thnks.
Anu
|
|
|
|
|
While it likely has nothing to do with your problem, your code needs a few changes:
CString ListBoxStr;
for(int i = 0; i < nosize; i++)
{
ListBoxStr.Format("%d", i+1);
int n = pCtrl->InsertItem(i, ListBoxStr);
ListBoxStr.Format("%s", rptime[i]);
pCtrl->SetItemText(n, 1, ListBoxStr);
}
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am using vc++ dialog based application.I have two dialogs.in the second dialog i have an editbox to give a camera ip.what i want is when i give the ip in the edit box in second dialog,the vlc control in first dialog should play it..any code..
|
|
|
|
|
EN_SETFOCUSor EN_CHANGE are not helpful?
|
|
|
|
|
Is there any way to achieve the following syntax:
typedef int nothrow;
class my_class {
public:
template<typename T> void *search(int what);
};
template<typename T> void *my_class::search(int what) {throw "error";}
template<> void *my_class::search<nothrow>(int what) {return 0;}
int main() {
my_class c;
c.search<nothrow>(42);
c.search(42);
}
MSVC8 "could not deduce the template argument for 'T'". I tried changing the declaration to template<typename T = void> void *search(int what); but unfortunately "default template arguments are only allowed on class templates."
Thanks for your time.
|
|
|
|
|
|
Hi All,
If you, from a command prompt, enter "NSLOOKUP <enter>", your system's default name server (name and address) are echoed to the output window. Does anybody know how the command determines this? I'm coding in C++.
Thanks in advance.
- Dale
|
|
|
|
|
I am having an exact same code that I use in two applications, but in one application it is using more time to complete than the other. In one application it completes at 413Hz while in another application it completes in 280Hz. I checked to see if they r running at different loads while executing that code, but its not the case. Here is the code -
BYTE *buf1_ptr;
BYTE *buf2_ptr;
buf1_ptr = buf_f;
buf2_ptr = buf_b;
for ( i=0; i < total ; i = i + 1 )
{
if (*(buf1_ptr)>=*(buf2_ptr))
*(buf1_ptr) = *(buf1_ptr)-*(buf2_ptr);
else
*(buf1_ptr) = 0;
buf1_ptr++;
buf2_ptr++;
}
thts all it is doing, but I am not sure why there is difference in execution time . The 'total' is same in both applications.
thanks
PKNT
|
|
|
|
|
how many times did you time them?
|
|
|
|
|
many times, both in debug and release modes.... I still dont understand why its like tht....
PKNT
|
|
|
|
|
There are several possible explanations. For example, if your code is in a small application, it may fit into the cache and be executed without having to read memory. (The cache is in the CPU, but memory is on external chips which take longer to read.) This would run faster.
A larger application wouldn't all fit into the cache, so it would have to read from memory more often, which would be slower.
A similar effect can occur with small/large amounts of data.
If your code is by itself in a function, the compiler may assign register variables to your pointers, which are fast. If the code is embedded in a larger function, the registers may be assigned to other variables, which would slow down your loop.
Another possible explanation: If one of the applications has significantly more TRUE values for the if statement, it will do many more times as much work, which will be slower.
|
|
|
|
|