Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TTimer ?

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
Hi

I have been developing a application in which I need to use a on timer event, I have used the TTimer available with borland Builder however the interval seems to differ on differnt CPU's and on some even when set to 1 the interval is way to long.

I was thinking of using gettime and using the 100's of a second value however after designing this it appears it would be to erratic and CPU intensive.

If anyone can offer any information on other timing methods I would be very grateful.

Thanks.......
 
TTimer is very unreliable and slow because it is based on Win32 message WM_TIMER which has a very low priority, so if your application is receiving a lot of Win messages, timer msg. is probably the last one to arrive! Another thing is that, although you can set interval in milisec., timer is based on PC hardware clock which has a frequency of about 18hz, so 56ms is the shortest period you can get from it!

Instead, use windows' high-speed performance counters (API calls QueryPerformaceFrequency() and QueryPerformanceCounter() ). You can find an example how to use it in Win32SDK, it is very easy and straight-forward. Or, even faster is to use __asm rdtsc :) but it would probably be unnecessary!
 
In general it's a bad idea to base anything time-critical on Windows as it's not a real-time system. It can be relied upon to the extend that the times read out is ok but not to rely on that a event set to a certain time really occurs on that exact time.
In short, Windows is NOT a RTOS! (RTOS = Real-Time Operating System).

There are RTOS which can co-exist with Windows but Windows exist IN those RTOS.

Totte
 
Thanks for that, I'll have a look round
 
There is a 3rd party rewrite of TTimer called TThreadedTimer that is available for free. I inherited a project that uses TThreadedTimer to update an OpenGL windows and it seems to be pretty reliable and very responsive. It was written by Alan Garney and is available from his Hellix web site. (His TOpenGL gadget works very well too!):

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top