#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int GroupFind(vector<pair<int,int> > vecStream,int nMainStore,int GroupLength)
{
int i=0,j=0;
int t=0;
int n=nMainStore%vecStream.size();
if(n==0)
n+=vecStream.size();
j=(n-1)/GroupLength;
t=j*GroupLength;
int k=vecStream[j*GroupLength].second;
for(i=j*GroupLength;i<GroupLength*(j+1);i++)
{
if(k<vecStream[i].second||vecStream[i].first==0)
{
k=vecStream[i].second;
t=i;
}
}
return t;
}
//////////////////////////////////////////////////////////////////////////
//三种相联
int Connect(vector<int> nvec,int nLeafLength,int nCacheLength,int GroupLength,int nelect)
{
int i=0,j=0;;
int nHitTarget=0;
vector<vector<pair<int,int> > > leaf;
vector<pair<int,int> > vecStream;
pair<int,int> pNpiece;
vector<string> vecstr;
for(j=0;j<nCacheLength;j++)
{
pNpiece.first=-1;
pNpiece.second=0;
vecStream.push_back(pNpiece);
}
for(i=0;i<nvec.size();i++)
{
bool bflag=false;
for(j=0;j<nCacheLength;j++)
{
if(nvec[i]==vecStream[j].first)
{
bflag=true;
break;
}
}
if(bflag==true)
{
nHitTarget++;
for(int t=0;t<nCacheLength;t++)
{
vecStream[t].second++;
}
if (nelect==1)
{
vecStream[j].second=1;
}
vecstr.push_back("命中");
}
else
{
int t;
t=GroupFind(vecStream,nvec[i],GroupLength);
for( int t1=0;t1<nCacheLength;t1++)
{
vecStream[t1].second++;
}
if (vecStream[t].first==0)
{
vecstr.push_back("调进");
}
else
{
vecstr.push_back("替换");
}
vecStream[t].second=1;
vecStream[t].first=nvec[i];
}
leaf.push_back(vecStream);
}
////输出替换过程
for (j=0;j<vecStream.size();j++)
{
cout<<" ";
for ( i=0;i<leaf.size();i++)
{
cout.width(3);
cout<<(leaf[i])[j].first-1<<" ";
}
cout<<endl;
}
for ( i=0;i<leaf.size();i++)
{
cout.width(4);
cout<<vecstr[i]<<" ";
}
cout<<endl;
return nHitTarget;
}
int main(int argc, char* argv[])
{
int nHitTarget=0;
int GroupLength=0;
int nLeafLength,nCacheLength;
vector<int> nvec;
int ninput;
int nelect;
while (true)
{
cout<<"请选择映射方式:LFU(1);FIFO(2)"<<endl;
cin>>nelect;
cout<<"请输入页的个数,cache大小,请输入组的大小:"<<endl;
cin>>nLeafLength>>nCacheLength>>GroupLength;
cout<<"请输入地址流以空格隔开,以-1未结束位:"<<endl;
while(true)
{
cin>>ninput;
if(ninput==-1)
break;
else if(ninput<=nLeafLength)
{
nvec.push_back(ninput+1);
}
else
cout<<"输入错误!"<<endl;
}
switch(nelect)
{
case 1:
case 2:
nHitTarget= Connect(nvec,nLeafLength,nCacheLength,GroupLength,nelect);
break;
default:
break;
}
cout<<endl;
cout<<"命中率为:"<<(float)nHitTarget/nvec.size()<<endl;
system("pause");
system("cls");
nvec.clear();
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MainStore.rar (13个子文件)
MainStore
MainStore.opt 53KB
MainStore.plg 5KB
MainStore.ncb 41KB
MainStore.cpp 3KB
Debug
MainStore.exe 564KB
MainStore.pch 2.33MB
vc60.pdb 140KB
MainStore.obj 342KB
MainStore.pdb 1.13MB
vc60.idb 81KB
MainStore.ilk 813KB
MainStore.dsp 3KB
MainStore.dsw 541B
共 13 条
- 1
资源评论
- 普通网友2012-07-16还可以,能用
- sj3509040232012-06-25dos界面,有点小错误
- asd78532012-09-03DOS界面不够亲和。一般
yunruiyuanjian
- 粉丝: 5
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Docker容器配置进阶
- tensorflow-gpu-2.7.4-cp37-cp37m-manylinux2010-x86-64.whl
- 多段线、 圆、弧转多段线(仅我可见)
- tensorflow-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- yeyue-p8Yi4-ve4a83792.apk
- tensorflow-gpu-2.7.3-cp38-cp38-manylinux2010-x86-64.whl
- 五相感应电机矢量控制模型MATLAB
- RGLED (1) (1).circ
- IMG_20240427_215747.jpg
- python下前端WEB学习笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功