void log(){ time_t current = time(0); tm *ptm = localtime(¤t); stuf... }
Just want to be sure - do i need to release tm pointer allocated memory at the end of the method?
If you lose all pointers to a chunk of memory without deallocating that memory then you have a memory leak. Your program will continue to own that memory, but has no way of ever using it again. A very small memory leak is not a problem.
Which operator is used to deallocate the memory? Explanation: free operator is used to deallocate the memory.
Use the malloc() function to allocate memory in designated blocks and the new function to create memory in the free store (heap). To reallocate memory, the realloc() function is used.
No you should not deallocate it,the structure is statically allocated.
Check the 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With