How to use java to realize the optimal replacement Optimal algorithm in operating system
This article mainly introduces how to use java to achieve the best replacement Optimal algorithm in the operating system, the article is very detailed, has a certain reference value, interested friends must read it!
Swap instruction
The optimal permutation algorithm is a theoretical algorithm proposed by Belady in 1966. The obsolete page it chooses will never be used in the future, perhaps the page that will no longer be accessed for the longest (future) time. The use of the best replacement algorithm usually ensures that the lowest page missing rate is obtained. However, at present, people are unable to compare with it, among several pages in memory, which page will no longer be accessed in the longest time in the future, so the algorithm can not be implemented, but it can be used to evaluate other algorithms. This is explained now as follows.
Suppose the system assigns three physical blocks to a process, and consider the following page number reference string:
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1
When the process is running, the first three pages will be installed in memory, and the missing page will be interrupted when page 2 needs to be accessed later. At this point, OS will eliminate page 7 according to the best algorithm replacement algorithm. This is because page 0 will be the fifth page to be visited, page 1 will be the 14th page to be visited, page 7 will need to be introduced at a low rate of 18 visits, and so on.
The following is the source code implementation section:
Package chapter02;public class P175Optimal {/ / find out if the index public static int existEmpty (int [] place) {for (int I = 0; I < place I +) {if (place [I] = =-1) return I;} / / is not empty return-1;} / / find whether the element exists in the array public static boolean paramExist (int [] place,int param) {for (place I = 0; I < place.length) {for (place I = 0; I < place.length) Return true; +) {if (place [I] = = param) return true;} / / not empty return false;} / / get the maximum distance value public static int getMaxIndexOfNeed (int [] place,int [] block,int start) {/ / recent demand location int minBlockIndex =-1; int minPlaceIndex =-1; for (int PlaceIndex = 0 position PlaceIndex)