Solved

Timing in Visual C++ 5.0

Posted on 1998-07-17
5
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

752 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