Welcome to “Algorithms and the Beauty of Programming” ↑ pay attention to us!
This article was first published on the wechat official account “Beauty of Algorithms and Programming”. Welcome to follow and learn more about this series of blogs in time.
In the last lecture we gave you a focus on what memory management is, to give you a general understanding of memory management. In simple terms, programs need memory to run, and how you manage and allocate memory to those programs.
In this section, we introduce the simplest memory management scheme: single contiguous partition. Why is this allocation the easiest? Let’s do a detailed introduction.
The basic idea of single contiguous memory allocation is that only one process is in memory at a time. We split 4 gigabytes of memory into two parts, one for the operating system kernel and the other for user programs, and only one user program is in memory at a time. As shown in Figure 1-1:
Figure 1-1 Memory allocation for a single contiguous area
At time T1, process P1 needs 512MB of memory. Allocate the memory to process P1, as shown in figure 1-2.
At T2, there is process P2, which needs 1GB of memory. Due to the characteristic of single continuous area memory allocation, P1 is already running in the user area at this time. Even if the remaining memory is sufficient, P2 cannot run, and P2 can only run after P1 runs and the memory is released.
Figure 1-2 Memory distribution of process P1
From the above analysis you can see that this way of allocating memory is very simple, it can be said that no method is simpler than this. But the disadvantages are also obvious:
- Only one program can be run at a time, so multiple programs cannot be implemented;
- After running a process, even if there is enough remaining memory, the new process cannot be executed, and the execution can only be continued after the process is finished, so the memory utilization is quite low.
- If the memory required by the process is greater than the total size of the user program, the process will not be able to run, so there are significant constraints on which processes to run. Not all processes can run.
Believe to see here, everyone can feel should be, when we encounter problems, according to our experience will think of a simple solution, but after analysis we will find the solution to the problem will be a lot of problems, then we will analyze these problems, and puts forward a new method and so on, continuously put forward new problems, Constantly put forward new solutions to solve new problems, so that science and technology continue to progress.
Do you have any better ideas about memory management? Welcome to leave a message.