在 C++ 中,std::time_t 和 std::chrono::time_point 是用于存储日期和时间的类。使用 time_point 存储时间是否有效。貌似time_point支持的功能比较多,使用起来效率会不会比time_t低? time_point 实例的内存大小大约有多大? time_t 实例的大小是多少?
最佳答案
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
?
与您告诉它使用的数字类型大小相同。如果您使用一种方便的持续时间类型(如 seconds
),则可能是 64 位。检查 sizeof
是否重要。
What's the size of instance of time_t?
未指定,通常为 32 或 64 位。如果重要,请检查 sizeof
。如果它是 32,那么您可能会在几十年后遇到麻烦。
关于c++ - C++中time_t和time_point的使用效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28982544/