|
From: Per W. <pw...@ia...> - 2006-06-06 23:42:01
|
I don't know what minutes have to do with this.
Note that the timeval struct splitted the information into two fields,
since a 32-bit unsigned integer can't hold more than 4000 seconds in
us-resolution.
Since gettimeofday() stores very large numbers in the sec field - seconds
since 1970-01-01 00:00, you will get overflow if working with 32-bit
numbers. Either you should adjust your times based on the startup time of
your application, or you should perform the evaluation using a larger data
type. long long or __int64 should make sure that the information will fit
even if using a 32-bit processor.
Note also that the granularity of the usec field will depend on used
hardware.
/Per W
On Tue, 6 Jun 2006, Roger Furer wrote:
> microseconds = seconds / 1000000
> I don't know if the value you are retrieving is accurate to that degree
> of precision, but you must devide. Remember, seconds * 60 = minutes.
> Aloha,
> Roger
>
> David Chu wrote:
> > Hi All,
> >
> > I've a question on how to convert struct timeval into microsecond.
> >
> > #include <sys/time.h>
> > struct timeval {
> > time_t sec;
> > suseconds_t usec;
> > };
> >
> > What I'm doing right now is the follow:
> >
> > struct timeval currentTime;
> > long timeInLong;
> >
> > gettimeofday(¤tTime, 0);
> >
> > // converts sec to microseconds
> > timeInLong = currentTime.tv_sec * 1000000;
> >
> > // Adds the microsecond together with the converted second.
> > timeInLong += sendTime.tv_usec;
> >
> > Does this look correct to you guys?
> >
> > Thanks,
> >
> > David
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|