void log(){
time_t current = time(0);
tm *ptm = localtime(¤t);
stuf...
}
只是想确定一下 - 我需要在方法结束时释放 tm 指针分配的内存吗?
最佳答案
不,你不应该释放它,结构是静态分配的。
检查 documentation :
Return value
pointer to a static internalstd::tm
object on success, orNULL
otherwise. The structure may be shared betweenstd::gmtime
,std::localtime
, andstd::ctime
, and may be overwritten on each invocation.
关于c++ - 是否需要释放本地时间的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12212339/