当前位置:网站首页>Not used for the longest time recently
Not used for the longest time recently
2022-07-28 07:20:00 【▀】
Most recently unused (LRU) Page replacement algorithm is based on the page into memory after the use of decision-making . Because it's impossible to predict the future usage of each page , Can only use “ The recent past ” As “ The near future ” Approximation of , therefore ,LRU Replacement algorithm is to select the most recent unused page to be eliminated . The algorithm gives each page an access field , Used to record the time of a page since it was last visited t. When a page needs to be eliminated , Select an existing face t The most valuable , That is, the most recent unused page to be eliminated .
| Access page | 7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 | 0 | 3 | 2 | 1 | 2 | 0 | 1 | 7 | 0 | 1 |
| Physical block 1 | 7 | 7 | 7 | 2 | 2 | 4 | 4 | 4 | 0 | 1 | 1 | 1 | ||||||||
| Physical block 2 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 2 | 3 | 0 | 0 | |||||||||
| Physical block 3 | 1 | 1 | 3 | 3 | 2 | 2 | 3 | 2 | 2 | 7 |
#include<iostream>
#include<list>
#include<vector>
#include<iterator>
#include<fstream>
#include<algorithm>
using namespace std;
class Optimal
{
public:
int index;
int dis;
public:
friend istream & operator>>(istream & i, Optimal&o);
friend ostream & operator<<(ostream &s, const Optimal&o);
Optimal(int i)
{
this->index = i;
dis = 0;
}
Optimal()
{
dis = 0;
}
~Optimal()
{
}
bool operator<(Optimal&s)
{
if (this->dis < s.dis)
return true;
return false;
}
bool operator>(Optimal&s)
{
if (this->dis > s.dis)
return true;
return false;
}
bool operator==(const Optimal&s)
{
if (this->dis == s.dis)
return true;
return false;
}
};
istream & operator>>(istream & i, Optimal&o)
{
i >> o.index;
return i;
}
ostream & operator<<(ostream &s, const Optimal&o)
{
s << "[" << "***" << o.index << "***" << "\t" << o.dis << "]";
return s;
}
void main()
{
fstream out("data.txt");
list<Optimal> v;
list<Optimal> w;
list<Optimal> l;
copy(istream_iterator<Optimal>(out), istream_iterator<Optimal>(), back_inserter(v));
//copy(v.begin(),v.end(),ostream_iterator<Optimal>(cout,"\t"));
while (v.size())
{
if (w.size() < 3)
{
Optimal p = v.front();
v.pop_front();
w.push_front(p);
l.push_back(p);
copy(w.begin(), w.end(), ostream_iterator<Optimal>(cout, "\t"));
cout << endl;
}
else
{
bool istrue = false;
for (auto ib = w.begin(); ib != w.end(); ib++)
{
if (ib->index == v.front().index)
{
istrue = true;
}
}
if (istrue == false)
{
for (auto ib = w.begin(); ib != w.end(); ib++)
{
int x = 0;
for (auto vib = l.rbegin(); vib != l.rend(); vib++)
{
if ((*ib).index == (*vib).index)
{
break;
}
(*ib).dis = ++x;
}
}
list<Optimal>::iterator s = max_element(w.begin(), w.end());
w.remove(*s);
Optimal p = v.front();
v.pop_front();
l.push_back(p);
w.push_front(p);
copy(w.begin(), w.end(), ostream_iterator<Optimal>(cout, "\t"));
cout << endl;
}
else
{
Optimal p = v.front();
v.pop_front();
l.push_back(p);
}
}
}
cin.get();
}data.txt file

test result :

边栏推荐
猜你喜欢

Basic knowledge of functions and special points

win下安装nessus

Redis sentinel mode and cluster

Easypoi export table with echars chart

Generate create table creation SQL statement according to excel

Wangeditor (@4.7.15) - lightweight rich text editor

The.Joernindex database has no content after Joern runs

Deployment of elk log analysis system

OJ questions about fast and slow pointers in linked lists

Tailing microelectronics B91 general development board integrated into the trunk of openharmony community
随机推荐
High performance memory queue -disruptor
最近最久未使用
guava之guava cache
Shell--- function
分布式系分发展概览
Standard C language learning summary 6
How did tensor leak your memory / video memory
N天前的日期
Raspberry pie serial port
Read the IP and device information of the switch node in the XML file, Ping the device, and the exception is displayed in the list
起点中文网 字体反爬技术 网页可以显示数字字母 网页代码是乱码或空格
Standard C language learning summary 5
Tailing microelectronics B91 general development board integrated into the trunk of openharmony community
Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
Codesensor: convert the code into AST and then into text vector
List of papers on gestures
软考证书还能这样用!拿到证书=获得职称?
Layer 3 switching and VRRP
Use of C3d
joern运行后.joernindex数据库无内容