#Memory management refers to the technology of allocating and using computer memory resources when software is running. Its main purpose is to allocate efficiently and quickly, and to release and reclaim memory resources at the appropriate time.
A running program, such as a web browser in a personal computer or a Turing machine, is a process that converts data between the real world and computer memory, and then stores the data in the computer Inside memory (in computer science, a program is a collection of instructions, and a process is a running program on the computer). Memory can be physically organized in many ways, such as tape or disk, or microchips of small array capacity. Starting in the 1950s, computers became more complex and were connected to many types of memory. The task of memory management also becomes complex, and multiple processes must even be running at the same time on the same machine.
In memory, a program (operating system) continuously tracks the location of the entity in each data block, and moves the data on the entity to improve its performance and ensure reliability, for each user layer (user -level) program, the operating system allocates a section of virtual memory space. When the process starts, there is no need to move data to the physical device. The data is stored in the virtual memory space on the disk, and there is no need to allocate main memory space to the process. , they will be freely loaded into the main memory when the user needs to use it.
You can imagine a large program. When it runs, it becomes a process, and most of the memory space is stored in the virtual memory address on the disk. The parts that are needed are loaded into the memory and provided. Serve.
Main memory usage
A program structure consists of the following two parts:
"This text block", also It is the instruction storage that provides CPU usage and operation
"data block", which stores the data set within the program itself, such as constant strings, such as some text messages within the GUI interface, or It is the message data that is put in during program design. The data can be added by input when the program is running, or it can be removed through the process of program running.
When a program runs, the operating system maps the program's data block and text block into the virtual memory space, and then runs the program's instructions in the memory. In any case, when the program is running When it is necessary to store temporary data, or more importantly, it will call some functions or routines (subroutine), and store the status of the current function. The best data structure method is that the data is stored in the stack. ). When we complete this function, the data will be taken out by the pop method of the stack. The stack will dynamically grow during the life cycle of the function. The operating system provides a distinction between text blocks and data blocks, while stack blocks At the top of a process, this approach is called segments or "segments"