是否需要释放本地时间的内存? [英] Does memory for localtime need to be deallocated?

查看:187
本文介绍了是否需要释放本地时间的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

只是想确定 - 需要释放tm指针分配的内存在方法的最后?

解决方案

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



请检查 文档 :: 成功时为静态内部 std :: tm 对象,否则为 NULL 。结构可以在 std :: gmtime std :: localtime std之间共享:: ctime ,并且可能在每次调用时被覆盖。



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

Just want to be sure - do i need to release tm pointer allocated memory at the end of the method?

解决方案

No you should not deallocate it,the structure is statically allocated.

Check the 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.

这篇关于是否需要释放本地时间的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆