C + + stack distribution and its setting method _ios

Source: Internet
Author: User

The memory used by a program compiled by C + + is divided into the following sections
1, stack area (stack)-by the compiler automatically assigned to release, hold the function of the parameter name, the name of the local variable. The operation is similar to the stack in the data structure.
2, heap area (heap)-assigned by the programmer to release, if the programmer does not release, the program at the end may be reclaimed by the OS. Note that it is different from the heap in the data structure, and the distribution is similar to the linked list.
3, Global zone (static area) (static)-the storage of global variables and static variables is placed in a piece, the initialization of global and static variables in a region, uninitialized global variables and uninitialized static variables in another adjacent area. The system is released after the program is finished.
4, literal constant area-a constant string is placed here, after the program is released by the system.
5, program code area-the binary code that holds the function body.

Copy Code code as follows:

int a = 0;//Global initialization area
char*p1;//Global Uninitialized Zone
Main ()
chars[] = "abc";//Stack
CHAR*P3 = "123456";//123456\0 in the constant area, p3 on the stack.
static int c =0;//Global (static) initialization area
P1 = (char*) malloc (10);
P2 = (char*) malloc (20);/The allocated 10 and 20 bytes of area are in the heap area.

strcpy (P1, "123456"); 123456\0 is placed in a constant area, and the compiler may optimize it with the "123456" that the P3 points to as a place.

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.