Solved

Sub-millisecond Timing in Windows 95

Posted on 1998-05-15
8
277 Views
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??
0
Comment
Question by:iasso
8 Comments
 
LVL 11

Expert Comment

by:alexo
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.
0
 

Author Comment

by:iasso
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??
0
 
LVL 1

Expert Comment

by:jwilcox
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.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 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.

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Expert Comment

by:RONSLOW
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.


0
 
LVL 10

Expert Comment

by:RONSLOW
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.
>>>>>>>>

0
 
LVL 10

Expert Comment

by:RONSLOW
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).

0
 
LVL 10

Expert Comment

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

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

759 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

24 Experts available now in Live!

Get 1:1 Help Now