Five basic memory allocation methods in C + +

Source: Internet
Author: User

Stackis the store of variables that are allocated by the compiler when needed and automatically purged when not needed. The variables inside are usually local variables, function parameters, and so on. In a process, the user stack at the top of the user's virtual address space is compiled with it to implement the function invocation. As with heaps, the user stack can expand and contract dynamically during program execution.

Heap , which is the memory blocks allocated by new, their release compiler does not go to the tube, by our application to control, generally a new will correspond to a delete. If the programmer does not release it, the operating system will automatically recycle after the program finishes. The heap can be expanded and shrunk dynamically.

The free storage area , which is the memory blocks allocated by malloc, is very similar to the heap, but it ends up living with no.

Global /static storage , global variables and static variables are allocated in the same piece of memory, in the previous C language, the global variables are divided into initialized and uninitialized (initialized global variables and static variables in a block, uninitialized global variables and static variables in another area adjacent, While uninitialized object stores can be accessed and manipulated through void*, the system frees itself after the program ends, there is no such distinction in C + +, and they occupy the same chunk of memory.

constant Storage , which is a special piece of storage, they are stored in constant, not allowed to modify (of course, you have to pass the improper means can also be modified, and many methods).

Five basic memory allocation methods in C + +

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.