do you need to free primitives in C

Started by
2 comments, last by Pfhorseti 21 years, 10 months ago
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?
-forseti
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.
great, thanks
-forseti
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
Forever trusting who we areAnd nothing else matters - Metallica

This topic is closed to new replies.

Advertisement