Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Timing in Visual C++ 5.0

Posted on 1998-07-17
5
Medium Priority
?
523 Views
Last Modified: 2013-12-14
How can i realize a 0.5ms (or less) timer in a console-application ?
Is it possible to do it without busy waiting
0
Comment
Question by:frefel
5 Comments
 

Author Comment

by:frefel
ID: 1168104
Edited text of question
0
 
LVL 2

Expert Comment

by:VEngineer
ID: 1168105

Most timer functions I've seen work in increments of integral milliseconds, not fractional.  Few timers are accurate at less than 100 ms.
0
 
LVL 4

Accepted Solution

by:
agreen earned 200 total points
ID: 1168106
Windows NT bases all of its timer support off of one system clock interrupt, which by default runs at a 10 millisecond granularity. This is therefore the resolution of standard Windows timers. When, for example, a multimedia application uses the timeBeginPeriod mutlimedia API, which is exported by the Windows NT dynamic link library WINMM.DLL, the call is redirected into the Windows NT kernel-mode function NtSetTimerResolution, which is exported by the native Windows NT library NTDLL.DLL. NtSetTimerResolution and NtQueryTimerResolution are defined as follows. All times are specifified in hundreds of nanoseconds.

NTSTATUS NtSetTimerResolution (
                           IN ULONG RequestedResolution,
                           IN BOOLEAN Set,
                           OUT PULONG ActualResolution
                   );

Parameters

                   RequestedResolution

                   The desired timer resolution. Must be within the legal range of system timer                     values supported by NT. On standard x86 systems this is 1-10 milliseconds.                    Values that are within the acceptable range are rounded to the next highest                    millisecond boundary by the standard x86 HAL. This parameter is ignored if                     the Set parameter is FALSE.

                   Set

                   This is TRUE if a new timer resolution is being requested, and FALSE if the                     application is indicating it no longer needs a previously implemented                    resolution.

                   ActualResolution

                   The timer resolution in effect after the call is returned in this parameter.

                   Comments

                   NtSetTimerResolution returns STATUS_SUCCESS if the resolution                                 requested is within the valid range of timer values. If Set is FALSE, the caller                    must have made a previous call to NtSetTimerResolution or
                   STATUS_TIMER_RESOLUTION_NOT_SET is returned.

NTSTATUS NtQueryTimerResolution (
                 OUT PULONG MinimumResolution,
                 OUT PULONG Maximum Resolution,
                 OUT PULONG ActualResolution
                 );

Parameters

                   MinimumResolution

                   The minimum timer resolution. On standard x86 systems this is 0x2625A,                       which is about 10 milliseconds

                   MaximumResolution

                   The maximum timer resolution. On standard x86 systems this is 0x2710,                    which is about 1 millisecond.

                   ActualResolution

                   This is the current resolution of the system clock.

Under Windows 95 you cannot change the timer resolution !!!
0
 
LVL 1

Expert Comment

by:Rajkumar_R
ID: 1168107
Yes you can realize timers even to the precision of micro seconds using select call !

Sample code :-

struct timeval      stTimeVal;
stTimeVal.tv_sec = 0;      // seconds feild !
stTimeVal.tv_usec = 1000 ; // 1milli second !

select (1,NULL,NULL,NULL,&stTimeVal); // this sleep for that much time !

If this works for you let me know i will repost my question as an answer(After you reject the current one) then you can give me points !
0
 

Expert Comment

by:joshual
ID: 1168108
You may like to read "Encapsulating Windows Timers in MFC (jan.1998)". at http://www.vcdj.com/

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question