Archived

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

simeygrimey

stack vs. heap memory

Recommended Posts

Local variables are allocated on the stack. Dynamically allocated ones reside on the heap. You don''t have much choice about it. As for which you use when: Use local variables for everything. When that''s impossible, use the heap.

Share this post


Link to post
Share on other sites
The stack is used by your program for passing arguments, remembering where to return after a function returns, and holding local variables. It is also limited in size, so try to avoid putting anything big on it, like an array for example, especially if your program has recursive functions.

Share this post


Link to post
Share on other sites
To add another descriptor to those given so far: Use the heap for all objects whose lifetimes extend past the return from the function call during which they were allocated.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites