how can I free the memory that I use for int, char, and other things? I want to free the memory after I use the variable.
how can I free the memory that I use for int, char, and other things? I want to free the memory after I use the variable.
Why do you want to do that in the first place? If it was an object it would make perfect sense, but why are you worrying about that for POD's? I don't think that's even possible.
Originally Posted by LinuxCoder
of course it is.
as for why? usually it's for scoping reasons, i.e. you want to create a variable that lives for longer then an automatic scope.Code:int *pInt = new int; // some code delete pInt;
bikr692002, please note that for "normal" stack variables
e.g.there's no need to free x's memory as it's done automatically at the end of x's scope.Code:void someFunc() { int x; }
if your memory is REALLY tight (and I'm talking embedded device with a few k's here) you can limit the scope of any stack variable by wrapping { }'s around it.
Code:void someBiggerFunc() { int x; // do lots of stuff { int y; // more stuff } // y has gone out of scope here x = 5; // x still ok }
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Objects can be POD (Plain Old Data).If it was an object it would make perfect sense, but why are you worrying about that for POD's?
@ChaosEngine:
Personally from his question i didn't think about variables allocated on the heap, probably just me but i thought his question was refering to deleting POD's allocated on the stack. My lapse i guess
@Tonto:
You're totally right, i employed the term incorrectly.
Yes, I got the impression he was going to try to free up memory for local stack variables too
Thanks, that helps alot.Originally Posted by ChaosEngine