Reputation: 564
In C++, std::time_t and std::chrono::time_point are classes for storing date and time. Is it efficient to use time_point to store the time. It seems that time_point supports more functions, will it be less efficient while using it compared with time_t? About how large in memory size is an instance of time_point? What's the size of instance of time_t?
Upvotes: 1
Views: 2461
Reputation: 254431
Is it efficient to use time_point to store the time.
Yes, it just contains a single numeric value.
It seems that time_point supports more functions, will it be less efficient while using it compared with time_t?
Why would you think that? Non-virtual functions don't increase the object size, and simple ones should be inlined so that they can be as efficient as messing around with the numeric value directly.
About how large in memory size is an instance of
time_point
?
The same size as the numeric type you told it to use. Probably 64 bits if you used one of the convenience duration types like seconds
. Check with sizeof
if it matters.
What's the size of instance of time_t?
Unspecified, typically 32 or 64 bits. Check with sizeof
if it matters. If it's 32, then you might run into trouble in a couple of decades' time.
Upvotes: 2