源程序的目的是设计一个请求页式存储管理方案,要求:每访问一个地址时,首要计算该地址所在的页的页号,然后查页表,判断该页是否在主存(虚拟的),如果该页在主存,则打印;如果不在且页框不满(页框为另一结构体),则调入页表并修改页表,打印页表;不在且页框满,则用LRU算法。
源程序为
#include<stdio.h>
#include<string.h>
#define AREA 1024
//#define True 1
//#define False 0
struct page_block //定义页框结构体
{
int pageblock;
char *judge;
static int count;
};//block[3];
struct page_block block[3];
struct page_num //定义页表结构体
{
int pagenum;
int pagenum_block;
char *state;
};//num[6];
struct page_num num[6];
/*********************************************************
**********初始化页表,页框********************************
*********************************************************/
void init_str()
{
int i, j;
for (i=0; i<3; i++) //初始化页框
{
block[i].pageblock = i;
block[i].judge = "False";
block[i].count = 0;
}
for (j=0; j<6; j++) //初始化页表
{
num[j].pagenum = j;
num[j].pagenum_block = 100;
num[j].state = "False";
}
}
/*/////////////////////////////////////////////
*****************判断页框是否为满**************
*//////////////////////////////////////////////
char *full()
{
int i = 2;
int count = 1;
while (strcmp(block[i].judge,"Ture") == 0)
{
i--;
++count;///////////////////////????count or block[i].count
}
if (count == 3)
{
return "False";
}
else
return "True";
}
/*///////////////////////////////////////////
*******************找到序号的位子*************
*/////////////////////////////////////////////
int locate()
{
int i = 0;
while (strcmp(block[i].judge,"True") == 0)
{
++i;
}
return i;
}
/*//////////////////////////////////////////////
*******************找到block中count为3的,*****
*******************也就是最早进入的*************
*////////////////////////////////////////////////
int find_block_num(int i)
{
int j;
while (num[j].pagenum_block != i)
{
++j;
}
return j;
}
/*//////////////////////////////////////////////
*******************页表与页框的调度*************
*////////////////////////////////////////////////
void find(int m)
{
int t;
int i;
int j;
t = m / AREA;
for (i=0; i<6; i++)
{
if (num[i].pagenum == t)
{
if (strcmp(num[i].state,"Ture") ==0)
{
block[num[t].pagenum_block].count = 0;
for (i=0; i<6; i++)
{
if (strcmp(num[i].state,"True") == 0)
{
++block[num[i].pagenum_block].count;
printf("输出页表的目前数据:\n");
printf("%d,%d,%s",num[i].pagenum, num[i].pagenum_block, num[i].state);
}
}
}
else if (strcmp(num[t].state,"False")==0 && strcmp(full(),"True")==0)
{
block[locate()].judge ="False";
++block[locate()].count;
num[t].pagenum_block = locate();
num[t].state = "True";
printf("输出页表的目前数据:\n");
printf("%d,%d,%s",num[t].pagenum, num[t].pagenum_block, num[t].state);
}
else for (i=0; i<3; i++)
{
if (block[i].count ==3)
{
j = find_block_num(i);
num[j].state = "False";
num[t].state = "Ture";
num[t].pagenum_block = num[j].pagenum_block;
num[j].pagenum_block = 100;
block[i].count = 0;
for (i=0; i<6; i++)
{
if (strcmp(num[i].state,"True") == 0)
{
++block[num[i].pagenum_block].count;
printf("输出页表的目前数据:\n");
printf("%d,%d,%s",num[i].pagenum, num[i].pagenum_block, num[i].state);
}
}
}
}
}
}
}
void main()
{
int m;
printf("请输入地址流:\n");
scanf("%d",&m);
find(m);
}
没有错误,但不能运行,提示为;
-------------------Configuration: yeb iao - Win32 Debug--------------------
Linking...
yeb iao.obj : error LNK2001: unresolved external symbol "public: static int page_block::count" (?count@page_block@@2HA)
Debug/yeb iao.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
yeb iao.exe - 2 error(s), 0 warning(s)
小弟不知道那地方错了,请教!!!!谢谢了!!!!