Jump to content
  • Advertisement
Sign in to follow this  

who allocates the memory (asctime)?

This topic is 4519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

own code made from sample code with only minor changes:
char *timestr;
struct tm *newtime;
time_t aclock;
newtime = localtime(&aclock);
timestr = asctime(newtime);
does asctime allocate memory to the timestr pointer that I have to release? Or what exactly does the timestr pointer point towards? AFAIK there's no char* entry in the tm struct, so the memory must come from somewhere else, or?! The question is - if I use the code above will I get a memory leak and do I have to release some memory that isn't released above?

Share this post

Link to post
Share on other sites
It is most likely that asctime simply returns the address of an internal buffer. This buffer is either not allocated dynamically (most probably this is the case, since it's fixed size anyway) or will eventually be freed by the CRT during program exit. The hint on MSDN supports this assumption:

Each call to this function destroys the result of the previous call.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!