I’m going to be developing a small dedicated server in C/C++ that will require uptime of forever. I’ve been looking into some time functions as millisecond timing is required for calculations. I have 2 problems that I’m facing:
-
Using a 32bit integer to store the number of milliseconds since the operation began will wrap around at about the 49 days mark resetting to zero. I have thought about using 64 bit integers, using gettimeofday to retrieve microseconds but this brings me to the second part.
-
There doesn’t seem to be any standard system calls for getting elapsed milliseconds that are platform independant
What should I do to resolve both these issues?
Use a 64bit integer, presuming that gives you enough time
You are correct; there is no standard. One possibility would be to use the Boost DateTime library, alternately find another or roll your own.
Good Luck!