• C

Sub-millisecond Timing in Windows 95

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??
iassoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alexoCommented:
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
iassoAuthor Commented:
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
jwilcoxCommented:
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

RONSLOWCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RONSLOWCommented:
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
RONSLOWCommented:
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
RONSLOWCommented:
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
RONSLOWCommented:
Also ,check out www.snippets.org and look for uclock.c which does micro-second timings.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.