时钟替换算法。arr - 是物理内存 arr2 - pages(虚拟内存)如果 arr 没有 page ,则替换具有 R=0 的帧;如果所有帧的 R=1;初始化所有R=0;IF 帧有页面和 R=1 。没做什么 。否则 R=1;
#include<iostream>
using namespace std;
struct Frame
{
char content;
int R;
};
int main()
{
int arr2[] = { 1, 2, 3, 4, 1, 2, 5, 6 };
Frame arr[3];
arr[0].R = 1;
arr[0].content = arr2[0];
arr[1].R = 1;
arr[1].content = arr2[1];
arr[2].R = 1;
arr[2].content = arr2[2];
arr[3].R = 1;
arr[3].content = arr2[3];
for (int i = 0; i < 3; i++)
{
for (int j = 4; j < 8; j++)
{
if ((arr[i].content == arr2[j]) && (arr[i].R = 1))
{
cout << "Frame have this page";
}
else if ((arr[i].content == arr2[j]) && (arr[i].R = 0))
{
arr[i].R = 1;
}
else if ((arr[i].content != arr2[j]) && (arr[i].R = 1))
{
arr[i].R = 0;
}
else
{
arr[i].content = arr2[j];
arr[i].R = 1;
}
}
}
for (int i = 0; i < 3; i++)
{
cout << arr[i].content << " " << arr[i].R << endl;
}
system("pause");
return 0;
}
Error 1 error LNK1168: cannot open C:\Users\h\Documents\Visual Studio 2013\Projects\os clock\Debug\os clock.exe for writing C:\Users\h\Documents\Visual Studio 2013\Projects\os clock \os 时钟\LINK os 时钟