gamecreator Posted August 27, 2019 Share Posted August 27, 2019 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). Quote Link to comment Share on other sites More sharing options...
Josh Posted August 28, 2019 Share Posted August 28, 2019 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. 1 Quote 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 More sharing options...
gamecreator Posted August 28, 2019 Author Share Posted August 28, 2019 I wonder if the functions could be reset. That way you could have a simple day variable in addition to the above and could run programs "forever." But also not hard to write your own time function for this, if you know how the function wraps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.