< go >stack and Heap

Source: Internet
Author: User

Stack Memory is a special region of your computer ' s memory, stores temporary variables created by each function (including the main() function). The stack is a "FILO" (first-in, last-out) data structure, which is managed and optimized by the CPU quite closely . Every time a function declares a new variable, it is "pushed" onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, is freed (tha T was to say, they was deleted). Once a stack variable is freed, which region of the memory becomes available for the other stack variables.

The heap is a region of your computer's memory that's not managed automatically for you, and are not as tight Ly managedby the CPU. It's a more free-floating region of memory (and is larger). To allocate memory on the heap, you must use malloc() or calloc() , which is built-in C functions. Once you had allocated memory on the heap and you were responsible for using to free() deallocate that memory Once you don ' t need itany more. If you fail-to-do, the your program would have a memory leakthat is known as a. That's, memory on the heap would still be set aside (andwon ' t being availableto other processes). This can leads to a slower PC, as there isn ' t as much memory for other processes.

                                

by JBuildz17

http://forum.brackeys.com/thread/what-are-the-differences-between-stack-and-heap-memory-allocation-c/

< go >stack and Heap

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.