Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Pfhorseti

do you need to free primitives in C

This topic is 5864 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

Hi, The subject is kind of self-explanatory but do i need to manually free primitives in C? if so, how would you do it?

Share this post


Link to post
Share on other sites
Advertisement
Primitives like int, char, etc.? Not unless you dynamically allocate it. As long as you don''t do anything like int *pMyInt = new int;, you don''t have to.

Share this post


Link to post
Share on other sites
quote:
Original post by Pfhorseti
Hi,

The subject is kind of self-explanatory but do i need to manually free primitives in C?
if so, how would you do it?


quote:
Original post by Melraidin
Primitives like int, char, etc.? Not unless you dynamically allocate it. As long as you don''t do anything like int *pMyInt = new int;, you don''t have to.


Are we talking about C, or C++?

IMO, Melraidins answer is basically correct, but if we are talking about C, there is no such thing like "new" in C. In C you allocate dynamic memory with malloc() and deallocate it with free() .
If that was just a typo, and Pfhorseti meant C++, then you allocate with new and deallocate with delete , or allocate with malloc() and deallocate with free() .

In C++, malloc()/free() are considered deprecated and should be avoided when possible (AFAIK).


Forever trusting who we are
And nothing else matters
- Metallica

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!