Does memory for localtime need to be deallocated?

后端 未结 2 1229
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 02:08
void log(){
    time_t current = time(0);
    tm *ptm = localtime(¤t);
        stuf...
}

Just want to be sure - do i need to release tm point

2条回答
  •  梦如初夏
    2021-02-07 03:02

    No, you shouldn't. This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the content of this structure is overwritten.

    So be careful with results - e.g. copy them immediately and don't store the pointer.

提交回复
热议问题