Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / timer reset at integer maximum variable?

Author
Message
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 19th Jul 2011 01:44
Hi,

Does anyone know what happens to the system timer [timer()] when it reaches the maximum integer size (2,147,483,648?).

I am writing a program that will sit on a machine that could run for months and months and am left wondering what will happen to my timers.

At the moment I have some code that does something like this:

if timer() < previous_timer then Reset_Timer_Values()

Presumably thats all i'm going to have to do? I'm still left wondering what happens when the timer() return value becomes high, and whether the system timer resets at any value.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 19th Jul 2011 01:58
This won't happen until 2018, but I'm not sure what will happen to the timer() function itself, so that's hard to answer for me. Sorry I couldn't be of more help.

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 19th Jul 2011 02:36
Quote: "This won't happen until 2018"

Are you sure about that?
As I have always thought it to work, the value returned by timer() is the number of milliseconds that have passed since the system was turned on. Given that, and assuming it is represented using an unsigned integer (thus having a maximum "capacity" of 2^32 - 1 milliseconds), it would (supposedly) wrap around roughly every 50 days.


"Why do programmers get Halloween and Christmas mixed up?"
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 19th Jul 2011 03:10
Yeah I think the check you're doing is the only way to protect yourself against the rollover.


A 3D marble platformer using Newton physics.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 19th Jul 2011 03:43 Edited at: 19th Jul 2011 03:49


I guess that would work for the forseeable future if you don't want to have to implement that resetting function.

Edit: you may want to add some check variable to the above as well, as it will mess up if time > lastTime when the wrap-around occurs for the second or latter time.


"Why do programmers get Halloween and Christmas mixed up?"
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 19th Jul 2011 06:22
OK. Thanks everybody. I thought as much.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Jul 2011 10:14
You could use IanM's HITIMER(), which you can reduce the frequency of significantly.

For example, HITIMER(0.1) will give you a timer with a frequency of 100ms, giving you months of timing. If you need a 1 second frequency - HITIMER(1) then you have years!

http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_02/hitimer.html

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2011 15:40
If you are worrying about timer wrap-over, then you're probably doing it wrong!

Don't compare the current timer value to the previous one - subtract the previous value from the current value, then compare against the difference instead. You'll find that this works perfectly, even in the case of wrap-over.

Example:


Aternatively, you can use the TICKER commands in the plug-in that BatVink pointed out - it works in this way already.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Jul 2011 20:06
Is the Timer() not just milliseconds from midnight, rather than from system on time?

My signature is NOT a moderator plaything! Stop changing it!
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 19th Jul 2011 20:39
My timer() is at 27 hours, so I'm guessing it's not a midnight rollover.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Jul 2011 00:50
I believe it starts counting from a cold boot. I'm not too sure what happens when you hibernate, but I've a feeling it simply suspends the timer, and then resumes it when the machine is woken.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 20th Jul 2011 02:52 Edited at: 20th Jul 2011 02:59
Oops, my bad. I was thinking of the 2038 problem, and even then, it's unrelated.

Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 20th Jul 2011 22:44
Again, thanks for all the help people.

I like IanM's method of making the timer relative rather than absolute. Much better than what I was doing. Brain updated....

Login to post a reply

Server time is: 2026-07-10 22:37:35
Your offset time is: 2026-07-10 22:37:35