页面置换算法实验报告 下载本文

内容发布更新时间 : 2024/5/22 9:47:05星期一 下面是文章的全部内容请认真阅读。

}

}

UpdateData(false);

void CMyDlg::OnRadio1() {

// TODO: Add your control notification handler code here }

void CMyDlg::OnRadio2() {

// TODO: Add your control notification handler code here }

void CMyDlg::OnRadio3()

{

// TODO: Add your control notification handler code here }

void CMyDlg::OnChangeEdit2() {

// TODO: If this is a RICHEDIT control, the control will not

// send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here }

void CMyDlg::OnButton2() {

// TODO: Add your control notification handler code here MessageBox(_T(\确认退出?\ ExitProcess(0); }

void CMyDlg::OnButton3() {

UpdateData(true);

21

Input();

Pro*page=new Pro[N];

for(int j=0;j

//FIFO页面置换 n1=0;//记录缺页数 while(i1

页数加一

}

if(Search(p[i1].num,page,N)>=0) ++i1;//找到相同的页面

else { n1++; page[t1].num=p[i1].num/10;//如果没有找到相同的页,则进行页面替换,缺 }

t1=(++t1)%N; i1++; page[j].num=-1; page[j].time=j;

s1=1-n1/M; //LRU页面置换

int p2;

float n2=0;//记录缺页数 int tt,t2;tt=t2=0;

int i2=0;

for(j=0;j

page[j].num=-1; page[j].time=0; while(i2

int k;

k=Search(p[i2].num,page,N); if(k>=0) {

page[k].time=0;

for(p2=0;p2

22

}

} else { }

{ }

if(p2!=k)

page[p2].time++;

if(tt

n2++;

page[t2].num=p[i2].num/10;//如果没有找到相同的页,则进行++tt; t2++;

page[t2].time=0; else { n2++;

t2=Max(page,N);

page[t2].num=p[i2].num/10;

页面替换,缺页数加一

page[t2].time=0; }

for(p2=0;p2

if(p2!=t2) page[p2].time++; }

i2++;

s2=1-n2/M;

//OPT页面置换 int i3=0;

float n3=0;//记录缺页数 int t3=0;

int ttt=0;

for(j=0;j

page[j].num=-1; page[j].time=j; while(i3

23

{

if(Search(p[i3].num,page,N)>=0) i3++; else {

if(ttt

page[t3].num=p[i3].num/10;//如果没有找到相同的页,则进行

页面替换,缺页数加一

}

++ttt; t3++; i3++;

}

else if(ttt>=N) { int temp=-1,cn;

for(t3=0;t3

if(temp

}

}

page[cn].num=p[i3].num/10; n3++;

i3++;

} else break;

}

}

s3=1-n3/M; CString st,kg,bt; st=\

kg=\ \

bt=\命中率分别为:\

st.Format(\MessageBox(st,\命中率比较\UpdateData(false);

24

10.课程设计小结

这次实验相对于以前来说比较不一样的是对于界面的制作,是一个比较新奇的体验。整体来说的话还算是比较简单,需要注意的是在编写程序之前要将课程设计的要求及解决思路。通过此次实验,加深了对操作系统的认识,了解了操作系统中各种资源分配算法的实现,特别是对虚拟存储和页面置换有了一定的了解。

25