Jump to content

What happens when Millisecs() and GetCurrent() max out?


gamecreator
 Share

Recommended Posts

This is mostly just a curiosity question.  Time::Millisecs() and Time::GetCurrent() both return milliseconds as long, which has a maximum value of 2,147,483,647 (LONG_MAX).  This equates to almost 25 days, if my math is correct.  What happens when these functions max out?  Do they next go to 0, do they wrap to -2,147,483,648 (LONG_MIN) or something else?  I'm sure this won't affect most people here but it could be relevant for a server that's up 24/7 (I have no plans for this myself).

Link to comment
Share on other sites

In Turbo, I switched this to a uint64_t value. On Windows, internally, the function uses timeGetTime(). However, this function returns a DWORD value, which is an unsigned 32-bit integer.

Quote

Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days. This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.

This is actually pretty surprising. For games and even game servers, it is unlikely to cause problems but I can imagine a lot of other applications that run for months or years at a time that would encounter problems with this.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...