C ++ memory allocation methods-heap, stack, free storage, global/static storage, and constant Storage

Source: Internet
Author: User

C ++ memory allocation methods-heap, stack, free storage, global/static storage, and constant Storage
Stack is the storage area for variables allocated by the compiler when needed and automatically cleared when not needed. The variables are usually local variables and function parameters. In a process, the user stack is located at the top of the user's virtual address space, and the compiler uses it to call functions. Heap is the memory blocks allocated by new. Their release compilers are not controlled and controlled by our applications. Generally, a new compiler corresponds to a delete. If the programmer does not release the program, the operating system will automatically recycle it after the program is completed. The heap can be dynamically expanded and reduced. The free storage zone is the memory blocks allocated by malloc and so on. It is very similar to the heap, but it uses free to end its own life. In the global/static storage area, global variables and static variables are allocated to the same memory. In the previous C language, the global variables are divided into initialized and uninitialized (the initialized global variables and static variables are in one area, and the uninitialized global variables and static variables are in another adjacent area, objects that are not initialized at the same time can be accessed and manipulated through void *, and are released by the system after the program ends. This distinction is not found in C ++, they share the same memory zone. Constant storage area, which is a special storage area. It stores constants and cannot be modified (of course, you can modify them by improper means, and there are many methods)

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.