ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > student directories >
homework8 Version 0
👤 Author: by 15988816214163com 2019-12-24 01:54:29
Think of the page as a loop buffer, replaced by a loop. This is the simplest algorithm to implement, and the underlying logic is to replace the page that stays in memory the longest. However, because some programs or data are used frequently throughout the life of the program, it can lead to repeated swapping in and out.

#include<vector>

class Queue{
public:
Queue(const int capacity = 4):capacity(capacity),cur_front(0),cur_rear(0){
/*初始化队列大小为capacity,将cur_front与cur_rear的值初始化为0*/
for(int i = 0; i != this->capacity; ++i)
myqueue.push_back(0);
}
bool push(const int e){
/*添加元素e至队列尾部*/
}
bool pop(void){
/*将队列头部位置的元素弹出*/
}
bool existed(const int e){
/*如果队列中存在元素e,返回true,否则返回false*/
}
int front(void) const{
//返回队列的首元素
return myqueue[cur_front];
}
private:
int capacity;//队列大小
vector<int> myqueue;//数组
int cur_front;//游标,指向队列的头部位置
int cur_rear;//游标,指向队列的尾部位置
};

Regarding the page to be executed as a sequential array pages, the implementation steps of fifo algorithm for the page to be executed are as follows:

1. Search for page in memory
2. If the page is found, the page has been loaded, so there is no need to load again. Step 1 is returned to process the next page to be executed
3. If not found, the page is not loaded. Try loading the page into memory
4. If there is not enough memory, return to step 1 to process the next page after loading successfully
5. If the load fails, the memory is full. At this point, pop up the page in the head of memory and load the page to the tail again

Please login to reply. Login

Reversion History

Loading...
No reversions found.