Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Sub-millisecond Timing in Windows 95

Posted on 1998-05-15
Medium Priority
Last Modified: 2008-02-01
Using Visual C++ in Windows 95,  I am trying to have an event occur exactly every 1 millisecond.  I would acctually like it to occur every 500 microseconds but I don't think I can get that kind of resultion.  The MMTIMER is supposed to support 1ms time intervals, but by events occur later and it is not very precise(running on a P-200).  Is this a possible task??  Can I get events to precisly occur this quickly??
Question by:iasso
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
LVL 11

Expert Comment

ID: 1250774
First of all, please keep in mind that Win95 is NOT a real-time OS.  Not even remotely.  There is no way to guarentee EXACT timing in your app.  Your threads may be preempted by other apps or the system; interrupts may occur; etc...

With that in mind, the best resolusion is obtained using multimedia timers.  Check the timeSetEvent() function.

Author Comment

ID: 1250775
I know that the multimedia timers give you the best resultion.  My problem is that the resution they give is not good enough.  I'm asking if it is possible.  I know it is not possible using the standard MFC.  Can code be written below the OS level??  Or perhaps if you thunk a 16-bit code appltication you can get better resution than the multimedia timer provide.  I'm not sure how the Win 95 event handling works.  I know when some games load, Alt-tab and other WIN 95 functions do not work.  This is done to increase performance.  Is there a way to give a specific event greater priority??

Expert Comment

ID: 1250776
A specific event, I am not sure of, but processes and threads can be given higher priorities than other processes/threads(or lower) so that they get a bigger slice of the CPU time, so I guess you could probably put this specific task in its own thread, pump its thread priority to the highest, and give its process a slightly raised priority(unless you think its really mission critical, then you could really boost that up too) and get a bit better timing.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 10

Accepted Solution

RONSLOW earned 300 total points
ID: 1250777
thread priority can be changed without your consent by the OS.  So that won't help.

The multimedia timers are not MFC .. they ARE O/S calls.

If you are running on a pentium, then there are routines for accurate timing (I think i can dig some out for you).

Also, there are the profiling API's that may help.

Also, if you really want to be accurate, you should probably write a VxD instead .. that way you can avoid being interrupted partway thru.

I'll see what extra info on these I can dig up for you.

LVL 10

Expert Comment

ID: 1250778
The August 96 Windows Developers Journal has an article and source code on "A More Accurate Timing Tool"

You can get the source code (not sure about the article) from http://www.wdj.com

The code is assembler.

LVL 10

Expert Comment

ID: 1250779
Look at QueryPerformanceCounter and QueryPerformanceResolution

The docs say ...

High-Resolution Timer

A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.

LVL 10

Expert Comment

ID: 1250780
But as said before, if you need accurate timing, then it is best to do time-critical code in a VxD where you have some (better) control over your interrupts.

From a VxD you can call certainly call Get_System_Time (but that is only to the millisecond) .. I am not sure what other timers are or are not available in a VxD (I only have one that required millsecond timing, so Get_System_Time is ok).

LVL 10

Expert Comment

ID: 1250781
Also ,check out www.snippets.org and look for uclock.c which does micro-second timings.


Featured Post

Industry Leaders: 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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

604 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