当前位置:网站首页>最近最久未使用
最近最久未使用
2022-07-28 05:30:00 【▀】
最近最久未使用(LRU)的页面置换算法是根据页面调入内存后的使用情况做出决策的。由于无法预测各页面将来的使用情况,只能利用“最近的过去”作为“最近的将来”的近似,因此,LRU置换算法是选择最近最久未使用的页面予以淘汰。该算法赋予每个页面一个访问字段,用来记录一个页面自上次被访问以来所经历的时间t。当需要淘汰一个页面时,选择现有也面中t值最大的,即最近最久未使用的页面予以淘汰。
| 访问页面 | 7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 | 0 | 3 | 2 | 1 | 2 | 0 | 1 | 7 | 0 | 1 |
| 物理块1 | 7 | 7 | 7 | 2 | 2 | 4 | 4 | 4 | 0 | 1 | 1 | 1 | ||||||||
| 物理块2 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 2 | 3 | 0 | 0 | |||||||||
| 物理块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文件

测试结果:

边栏推荐
- MOOC Weng Kai C language week 8: pointer and string: 1. Pointer 2. Character type 3. String 4. String calculation
- MySQL查询父节点下面的所有子孙节点,查询用户列表时多级(公司)部门处理,根据反射,递归树形结构工具类
- Gd32f407 porting freertos+lwip
- Redis主从复制原理及配置
- Sysevr environment configuration: joern-0.3.1, neo4j-2.1.5, py2neo2.0
- VNC Timed out waiting for a response from the computer
- Svg understanding and drawing application
- 在转化词向量之前先转化为AST再转化为词向量的实现方法
- Reptile learning summary
- shell---函数
猜你喜欢

easypoi一对多,合并单元格,并且根据内容自适应行高

Reptile learning summary

shell---函数

Bond mode configuration

Deployment of elk log analysis system

VLAN configuration

PXE unattended installation management

Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures

GFS分布式文件系统

Leetcode then a deep copy of the linked list
随机推荐
MySQL queries all descendant nodes under the parent node. When querying the user list, it is processed by multi-level (company) departments. According to reflection, it recurses the tree structure too
RAID磁盘阵列
Asynchronous programming promise
N天前的日期
RAID disk array
一个定时任务提醒工具
Addition, deletion, check and modification of sequence table
Branch and loop statements
JS string method Encyclopedia
Gd32f407 porting freertos+lwip
分解路径为目录名和文件名的方法
Three cache technologies -- localstorage, sessionstorage, cookies
Joern的代码使用-devign
codesensor:将代码转化为ast后再转化为文本向量
MOOC Weng Kai C language week 7: array operation: 1. array operation 2. Search 3. preliminary sorting
三层交换和VRRP
Codesensor: convert the code into AST and then into text vector
Shell--- function
视频格式基础知识:让你了解MKV、MP4、H.265、码率、色深等等
Bond mode configuration