02. C ++ core programming

1. memory partition model

  C ++ program is executed, the general direction of the memory is divided into four regions:

    Code area: storing binary code function body, managed by the operating system

    Global Area: store global variables and static variables and constants

    Stack Area: allocated by the compiler automatically released, the stored function parameters, local variables, etc.

    Heap: the allocation and release by the programmer, if the programmer does not release at the end of the program by the operating system recovery

  Memory 4 zone meaning:

    Data stored in different areas, giving different life cycles, giving us greater flexibility program

  1.1 before running

    After the program is compiled, executable program generated exe, before execution of the program is not divided into two regions

    Code area:

      The machine instruction executed by the CPU

      Code area is shared , shared purpose for the program is executed frequently, you only need to have a code to memory.

      Code area is read-only , because it is read-only to prevent accidental modification of its program instructions.

    Global Area:

      Global and static variables are placed in this

      Global zone also contains a constant region, string constants, and other constants are also stored here.

      The data area is freed by the operating system after the end of the program.

    to sum up:

      C ++ is divided into zones and the global zone before running the code

      Code area is characterized by shared and read-only

      Global Area stored in global variables, static variables, constants

      Constant region stored const modified global constants and string constants

  After running 1.2

    Stack area:

      Automatically allocated by the compiler release, storage parameter value of the function, local variables, etc.

      Note: Do not return address local variables, stack area to open up data automatically released by the compiler

    Heap:

      Assigned by the programmer release, if the programmer does not release at the end of the program by the operating system recovery

      In C ++, as long as the use of new open memory in the heap area

  1.3 new operator

Guess you like

Origin www.cnblogs.com/ccczf/p/12134323.html