Solved

Timing in Visual C++ 5.0

Posted on 1998-07-17
5
503 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to find missing packages when using Netbeans IDE 8.1 ? 19 46
FMX enumerated colours 2 84
Issues with C++ Class 19 80
eclipse apache tomcat admin console 39 46
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now