Search code examples
c++cdedicated-server

Cross platform millisecond timer lasting more than 49 days?


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:

  1. 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.

  2. 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?


Solution

    1. Use a 64bit integer, presuming that gives you enough time

    2. 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!