• Advertisement

Archived

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

stack vs. heap memory

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

Advertisement
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

  • Advertisement