C ++ memory storage management

BSS (Block Started by Symbol) usually refers to a memory area used to store uninitialized global variables and static variables in the program. The characteristics are: readable and writable, BSS segment will be cleared automatically before the program is executed. Therefore, the uninitialized global variable has become 0 before the program is executed.

Data segment: Data segment usually refers to a memory area used to store initialized global variables in the program. The data segment belongs to static memory allocation.

Code segment: Code segment (code segment / text segment) usually refers to a memory area used to store program execution code. The size of this area is determined before the program runs, and the memory area is usually read-only. Some architectures also allow the code segment to be writable, that is, allow the program to be modified. In the code segment, it is also possible to include some read-only constant variables, such as string constants.

Heap (heap): Heap is used to store the dynamically allocated memory segment in the process of running, its size is not fixed, can be dynamically expanded or reduced. When the process calls malloc and other functions to allocate memory, the newly allocated memory is dynamically added to the heap (heap is expanded); when using free and other functions to release memory, the released memory is removed from the heap (heap is reduced)

Stack (stack): the stack is also called the stack, which is a local variable temporarily created by the user to store the program, that is to say, the variable defined in our function bracket "{}" (but does not include the statically declared variable, static means in the data segment Store variables). In addition, when the function is called, its parameters will also be pushed into the calling process stack, and after the call ends, the function's return value will also be stored back on the stack. Due to the advanced, late-out feature of the stack, the stack is particularly convenient for saving / restoring the call site. In this sense, we can think of the stack as a memory area for registering and exchanging temporary data

Published 9 original articles · liked 0 · visits 253

Guess you like

Origin blog.csdn.net/a_465240/article/details/105464915