title: Why would you ever want to allocate memory on the heap rather than the stack?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/102009/when-is-it-best-to-use-a-stack-instead-of-a-heap-and-vice-versa">When is it best to use a Stack instead of a Heap and vice versa?</a>  </p>
  </blockquote>
  
  <p>I've read a few of the other questions regarding the heap vs stack, but they seem to focus more on what the heap/stack do rather than why you would use them.</p>
  
  <p>It seems to me that stack allocation would almost always be preferred since it is quicker (just moving the stack pointer vs looking for free space in the heap), and you don't have to manually free allocated memory when you're done using it. The only reason I can see for using heap allocation is if you wanted to create an object in a function and then use it outside that functions scope, since stack allocated memory is automatically unallocated after returning from the function.</p>
  
  <p>Are there other reasons for using heap allocation instead of stack allocation that I am not aware of? </p>