It discusses the C / C ++ in the heap, stack, free store, global / static memory and a constant memory area code segment data segment .bss.

It discusses the C / C ++ in the heap, stack, free store, global / static memory and a constant memory area code segment data segment .bss.

Heap : those that block of memory allocated by malloc and so on, he and the heap is very similar, but it is free to end their lives.

Stack : is the storage area when needed those allocated by the compiler, automatically cleared when no longer needed variables. Variables which are typically local variables, functions and other parameters. In one process, located at the top of the user virtual address space is the user stack, the compiler uses to achieve the function was called. And the stack, users stack may expand and contract to dynamically during program execution.

Free store : those that block of memory allocated by new, never mind their release compiler, to control by our application, a new general would correspond to a delete. If a programmer is not freed, then at the end of the program, the operating system will automatically recover. Heap can dynamically expand and contract.

Global / static memory : global and static variables are allocated to the same memory, the previous C language, is divided into global variables initialized and uninitialized (initialized global and static variables in a region, not initialized global variables and static variables in an area adjacent to another, while uninitialized object store can be accessed and manipulated through a void *, released by the end of the program on their own systems), no such distinction in C ++, and they jointly occupy the same memory area.

Constant storage area : This is a special storage area inside the store they are constant, not allowed to modify (Of course, you can also change through non-legitimate means, and the many ways)

.BSS segment : BSS section (bss segment) generally refers to an area of memory used to store program uninitialized global variables. BSS is the English abbreviation Block Started by Symbol. BSS segment is a static memory allocation.
Data segments : the data segment (data segment) generally refers to an area of memory used to store program initialized global variables. Data segment is a static memory allocation.

Code segment : code segments (code segment / text segment) generally refers to an area of memory used to store program code executed. The size of these partial areas have been identified before the program run, and usually belong to a read-only memory area, some architectures also allow for the code segment can be written, which allows to modify the program. In the code segment also may contain a constant read-only variables, such as string constants and the like. Code segment data is stored program code, if there are several machines the same process to run a program more, then they can use the same code.

Published 57 original articles · won praise 28 · views 4147

Guess you like

Origin blog.csdn.net/weixin_41747893/article/details/99339774