|
Bah, you beat me to it...
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Sorrreeeee
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Uhh, thanks, I´ll try that out in a moment.
Thanks for the writings on Windows Internals. Who could have known such a thing . Very interesting.
Two things, though. Why do you set a sleep time of 65ms (instead of infinite)? And I don´t see why this should circumvent the 15ms time-slice. QueryPerformanceCounter might 'see' higher resolution, but if the thread sleeps for 15ms, there´s nothing to see? Or is there?
Souldrift
|
|
|
|
|
The 65ms is just an example time - it can't be infinite because I want it to terminate The thing that's seeing past the 15.625 timer resolution is the TimerQueueTimer. That has a resolution of 1ms.
The program is intended to show that the timer callback is called with a resolution of 1ms, so could be used in your case, so long as your thread can remain the active thread.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Okay, I thought so (after some thinking). Now if you will bear with me one more time, I´m not quite sure how to understand (handle) this regarding my case.
For example if I use this (cause 9ms are appx. the time I need to wait before sending)
CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)&DoSendHere, 0 , 9, 1, WT_EXECUTEINTIMERTHREAD);
QueryPerformanceCounter(&liStart);
::SleepEx(65, TRUE);
The callback func should with a 65ms sleep be called like 7 times. Though my log shows 54.
I guess, this is because the timer doesn´t stop after my sleep or my sending. So the next question would be, how do I stop it? I know, i doesn´t even have to be periodic for what I need (so it would stop by itself), but I´m trying to understand the structure. I added a DeleteTimerQueueEx( hTimerQueue, NULL ); but it crashes now at that point.
Souldrift
Edit: And why does it not call the callback func when I take away the sleepEx()?? Is it dependant on the thread being asleep?
If I do this
CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)&DoSendHere, 0 , 1, 0, WT_EXECUTEINTIMERTHREAD);
QueryPerformanceCounter(&liStart);
::SleepEx(10, TRUE);
it doesn´t enter, either.
modified on Monday, July 6, 2009 4:32 AM
|
|
|
|
|
Souldrift wrote: CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)&DoSendHere, 0 , 9, 1, WT_EXECUTEINTIMERTHREAD);
You're asking for a timer with an initial delay of 9ms and periodic delays after that of 1ms.
Souldrift wrote: DeleteTimerQueueEx( hTimerQueue, NULL );
Think that should be DeleteTimerQueueTimer( hTimerQueue, hTimer, 0 ); . That worked for me, anyway.
Souldrift wrote: And why does it not call the callback func when I take away the sleepEx()?? Is it dependant on the thread being asleep?
The thread needs to be in an alertable state - look at the MSDN documentation[^] for what that means.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Souldrift wrote: it always jumps 15,6ms forward
I doubt the granularity and accuracy of the time value returned by ::GetSystemTimeAsFileTime() . Even though the FILETIME structure is a time value where the least significant bit represents 100 nanoseconds, it doesn't mean that it has an accuracy of 100 nanosecs.
It's like looking at your watch, measuring a time with the needle showing seconds and then multiplying the value by 1,000,000 and claim you measured with microsecond accuracy.
For time measurements of this kind you should you the performance timer; ::QueryPerformanceCounter() and ::QueryPerformanceFrequency() .
It will give you the best accuracy available on your hardware.
Read here[^] for more info on the high resolution performance counter.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
How can I make a trunc() function in C++,
Example:
trunc(7.1) = 7;
trunc(7.6) = 8;
|
|
|
|
|
What function? Just cast it to an integer. Or if you want a function:
__inline int trunc(float f)
{
return (int)f;
}
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
If I do it in this way, the results are:
trunc(7.1) = 7;
trunc(7.6) = 7;
|
|
|
|
|
Oh sorry, I overlooked your previous post. You can use one of those flooring or ceiling functions.
[Added] OK, Stuart just replied with a floor function at the same time. [/added]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Presuming you want similar behaviour for numbers < 0
trunc(-7.1) = -7;
trunc(-7.6) = -8;
then this should work
int trunc(double d) { return floor(d+0.5); }
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
rounded_num = (int)(num + (num < 0 ? -0.5 : 0.5));
|
|
|
|
|
You call it trunc() , but that is the expected behaviour of round() function.
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]
|
|
|
|
|
I was guessing that the OP is trying to implement the functionality himself.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Your guess is right, I suppose. However, OP must not give, even to his functions, deceiving names, unless, of course, he is a Klingon programmer.
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 are looking for a rounding function
int round(double d)
{
return (int) (d + 0.5);
}
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
The FPU already does this for you.
inline int iround(double v){
int retval;
__asm fld qword ptr [v]
__asm fistp dword ptr [retval]
return retval;
}
inline unsigned int uround(double v){
unsigned retval;
__asm fld qword ptr [v]
__asm fistp dword ptr [retval]
return retval;
}
|
|
|
|
|
|
Hiii,,,
The following code doesn't take .
How to make it correct?
UINT64 ui_offset;
LONGLONG ll_array[ ui_offset];
Showing constraint error....!!!
Thank u
|
|
|
|
|
ui_offset has to be a constant.
Try this -
const UINT64 ui_offset = <value>;
LONGLONG ll_array[ui_offset];
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hiiii....
I tried with
const UINT64 ui_offset = 1000000;
LONGLONG ll_array[ui_offset];
It works properly...
Thanking you......
|
|
|
|
|
What is woring in my following codes run time error is occuring for both code
int main()
{LPTSTR strResult;
LPTSTR strDefault=L"no";
DWORD d=255;
GetPrivateProfileString(L"data",L"Patchcab ",
strDefault,strResult,d,
L"D:\\TMP\\patchpolicy.ini");
printf("%s",strResult);
}
int main()
{
LPTSTR strResult=L"";
LPTSTR strDefault=L"no";
DWORD d=255;
GetPrivateProfileString(L"data",L"Patchcab ",strDefault,strResult
,d,L"D:\\TMP\\patchpolicy.ini");
printf("%s",strResult);
}
|
|
|
|
|
There is no memory allocated for the LpReturnedString parameter.
You're declaring it as LPTSTR strResult which is only a pointer.
You will need to do this -
TCHAR strResult[255];
DWORD d = 255;
Also change printf to _tprintf .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|