stack, heap, static memory

1. The stack is first in, last out,

2. The stack stores the maintenance information required for a function call, function parameters, function return address, local variables, and function call context. There are no functions without stacks, and no local variables.

3.

The stack holds the maintenance information required for a function call (function parameters, function return value address, local variables, function call context)

4. The data on the stack will be released after the function returns and cannot be passed to the outside of the function

5. The heap is a huge memory space in the program, which can be used freely by the program

6. The memory requested by the program in the heap will remain valid until the program actively releases it

7. Heap space can only be obtained by application

8. How the system manages the heap space (free linked list method, bitmap method, object pool method, etc.)

9. The program static storage area allocates space as the program runs until the end of the program.

10. The size of the static storage area has been determined at the compile time of the program

11. The static storage area of ​​the program is mainly used to save the global variables and static variables in the program

12. Unlike the stack, the information in the static storage area is eventually saved to the executable program.

Summarize:

The stack is mainly used for function calls, the heap area is mainly used for dynamic application and return of memory, and the static storage area is used to save global variables and static variables


memory layout

1. File header - code segment - data segment ((defined data - undetermined data) - static area)

2. The stack segment officially exists after the program runs and is the basis for the program to run

3. The bass segment stores uninitialized global variables and static variables

4. The text segment stores the executable code in the program

6. The data segment holds those global variables and static variables that have been initialized

7. The rodata segment stores constant values ​​in the program, such as string constants

8. Static storage area usually refers to the .bss and .data segments in the program

9. The read-only area usually refers to the .rodata segment in the program

10. The space occupied by local variables is the space on the stack

11. Dynamic space is the space in the heap

12. The executable code of the program is stored in the .text segment


scanf cannot input a string, the input string uses gets, vs for security reasons, you can use scanf_s to specify the input length, and fgets input the specified length from the file stream.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325951044&siteId=291194637