C + + memory management -1--c++ memory allocation method

Source: Internet
Author: User

Zone for C + + memory allocation:

1. Stack: Where the program is run, the local variables, and the incoming parameters are stored and recycled at the end of the program .

2. Heap: New assignment, released by delete

3. Free Storage area: malloc distribution

4. Global/Static storage: Where global variables or static variables are stored

5. Constant storage: Where constants are stored, modifications are not allowed

The difference between heap and stack:

1. Management in a different way, the heap is managed by the programmer itself, and the stack is managed by the compiler

2. The size of the space is different, the heap is basically unlimited, and the stack can easily overflow

3. Different growth modes, the heap is the address of the upward increase, and the stack is from the address of the high-to-low change

4. In different ways, the heap is dynamically allocated by the programmer itself, and the stack is freed by the compiler itself.

5. Fragmentation can occur, when a large number of dynamic allocation of memory is fragmented, affecting the execution efficiency of the program, but not on the stack, because the stack allocation

6. The efficiency of allocation is different, the heap allocates memory is inefficient

C + + memory management -1--c++ memory allocation method

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.