Board index » cppbuilder » Now() function

Now() function


2006-05-16 10:22:53 PM
cppbuilder69
Dear people,
i work with C++Builder 6.
1) i just read a note about the Now function, reading:
"Note: Although TDateTime values can represent milliseconds, Now is accurate
only to the nearest second."
The note is for the CLX reference.
Is it valid also for th VCL?
2) Is the Now() function thread-safe?
Best Regards,
Mauro Russo.
 
 

Re:Now() function

mauro russo wrote:
Quote
"Note: Although TDateTime values can represent milliseconds, Now is
accurate only to the nearest second."
Is it valid also for th VCL?

I don't believe so. I have used Now() down to tenths of a second at
least. As to what the practical resolution is I don't know but
considering it's part of the VCL which is message based I don't think
you should count on much better than tenths.
By that I mean that the individual resolution might be better than a
tenth but the chance of you being able to accurately and consistently
time something better than that using Now() I have doubts.
If you want to use it to skip screen updates so you only render
something every few tenths of a second it should be fine but don't try
timing hardware with it :)
Quote
2) Is the Now() function thread-safe?
If Now() is a wrapper function around an API call it probably is thread
safe but I don't know.
NB:Now() is also quite a slow function to call for some reason.
Bottom line:If you genuinely need a high resolution timer don't look at
Now() but if (as I have done) you just want to limit graphical updates
so they only have a dozen times a second it works fine.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Now() function

"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >wrote in the message
Quote
mauro russo wrote:

Bottom line:If you genuinely need a high resolution timer don't look at
Now()
what else to look? Really i need something like 0.05 seconds.
Thank you.
Quote
but if (as I have done) you just want to limit graphical updates
so they only have a dozen times a second it works fine.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

{smallsort}

Re:Now() function

Quote
what else to look? Really i need something like 0.05 seconds.
I personally prefer GetTickCount or timeGetTime (mmsystem.h), but for
extremely tight precision, use QueryPerformanceCounter.
HTH
Jonathan
------------------------
TwineCompiler, blazingly fast C++ compiles on ANY machine:
www.jomitech.com/
------------------------
 

Re:Now() function

Andrue Cope [TeamB] wrote:
Quote
NB:Now() is also quite a slow function to call for some reason.
Probably has to do with converting the OS's date and time unsigned
integers into a TDateTime floating point value, which probably
requires a divide.
 

Re:Now() function

"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
considering it's part of the VCL which is message based
<snip>
That has no relevance to this issue at all. There are no messages involved
when querying the system's date/time values.
Quote
I don't think you should count on much better than tenths.
The resolution of Now() is based on the resolution of the Win32 API
GetLocalTime() function.
Gambit
 

Re:Now() function

"mauro russo" < XXXX@XXXXX.COM >wrote in message
Quote
i just read a note about the Now function, reading:
"Note: Although TDateTime values can represent milliseconds, Now
is accurate only to the nearest second."

The note is for the CLX reference.
Is it valid also for th VCL?
The VCL version of Now() returns a TDateTime that contains milliseconds.
Quote
Is the Now() function thread-safe?
Yes.
Gambit
 

Re:Now() function

"mauro russo" < XXXX@XXXXX.COM >wrote in message
Quote
what else to look? Really i need something like 0.05 seconds.
What EXACTLY are you trying to accomplish in the first place? What are you
using Now() to do?
Gambit