c++ - 是否需要释放本地时间的内存?

标签 c++ memory-management

void log(){
    time_t current = time(0);
    tm *ptm = localtime(&current);
        stuf...
}

只是想确定一下 - 我需要在方法结束时释放 tm 指针分配的内存吗?

最佳答案

不,你不应该释放它,结构是静态分配的。

检查 documentation :

Return value
pointer to a static internal std::tm object on success, or NULL otherwise. The structure may be shared between std::gmtime, std::localtime, and std::ctime, and may be overwritten on each invocation.

关于c++ - 是否需要释放本地时间的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12212339/

相关文章:

c++ - boost buffer_sequence_adapter 中的奇怪编译错误

带有自定义 C++ 库的 PHP 扩展

c - 这个代码片段有什么问题

java - matcher.group() 的内存分配

c - malloc 中的内存泄漏?

java - 从 Java 中的复杂对象中释放内存

c++ - Windows:DLL 中的元信息

c++ - VS代码包含路径

c++ - "Unable to resolve template based identifier X"- 从模板类调用模板参数类的方法 (C++)

c - 在c中访问未初始化的内存