📄 unit1.~pas
字号:
for j:=FrontPosition to BehindPosition do
size:=size+table[j].Size;
table[FrontPosition].Size:=size;
length:=BehindPosition-FrontPosition;
for i:=0 to length-1 do
begin
start:=FrontPosition+1;
while start+1<=num-1 do
begin
table[start+1].Number:=table[start+1].Number-1;
table[start]:=table[start+1];
start:=start+1;
end;
num:=num-1;
end;//end for;
end;
//按size大小升序table
OrderTable;
end;
procedure TForm1.BitBtn10Click(Sender: TObject);
begin
TextToInt;
Num:=1;
table[Num-1].Number:=Num;
table[Num-1].Size:=300;
table[Num-1].Position:=0;
table[num-1].finish:='可用';//表示可用
Numed:=0;
NowHandUpWork:=0;
ExitData:=false;
if (exitData=false)then
if HandUpWork(NowHandUpWork)=true then printf;
NowHandUpWork:=1;
if (exitData=false)then
if HandUpWork(NowHandUpWork)=true then printf;
NowHandUpWork:=2;
end;
procedure TForm1.BitBtn11Click(Sender: TObject);
begin
if exitData=false then
begin
if(NowHandUpWork<10) then
begin
if HandUpWork(NowHandUpWork)=true then printf;
NowHandUpWork:=NowHandUpWork+1;
end
else ShowMessage('已没有作业了!');
end
else ShowMessage('因为没有空间被分配,所以分配停止!');
end;
procedure TForm1.BitBtn12Click(Sender: TObject);
begin
close
end;
procedure TForm1.AddToTable;
var
p:TListItem;
i:integer;
begin
Listview1.Items.Clear;
ListView2.Items.Clear;
for i:=0 to numed-1 do
begin
p:=ListView1.Items.Add;
p.Caption:=IntToStr(tableed[i].Number);
p.SubItems.Add(IntToStr(tableed[i].WorkNum));
p.SubItems.Add(IntToStr(tableed[i].Size));
p.SubItems.Add(IntToStr(tableed[i].Position));
p.SubItems.Add(tableed[i].finish);
end;
for i:=0 to num-1 do
begin
p:=ListView2.Items.Add;
p.Caption:=IntToStr(table[i].Number);
p.SubItems.Add(IntToStr(table[i].Size));
p.SubItems.Add(IntToStr(table[i].Position));
p.SubItems.Add(table[i].finish);
end;
end;
procedure TForm1.OrderTable;
var
MidNumber,Midsize,MidPosition,MidworkNum,i,j:integer;
Midfinish:string;
begin
//按size大小升序table
for i:=0 to num-2 do
begin
for j:=i+1 to num-1 do
if(table[i].Size>table[j].Size) then
begin
Midnumber:=table[i].Number;
Midsize:=table[i].Size;
Midposition:=table[i].Position;
Midworknum:=table[i].WorkNum;
Midfinish:=table[i].finish;
table[i]:=table[j];
table[j].Number:=Midnumber;
table[j].Size:=Midsize;
table[j].Position:=Midposition;
table[j].WorkNum:=Midworknum;
table[j].finish:=Midfinish;
end;
table[i].Number:=i+1;
table[i+1].Number:=i+2;
end;
end;
procedure TForm1.UPClick(Sender: TObject);
begin
if TextToInt3=true then
begin
Fifo_Lru;
printf3;
end;
end;
procedure TForm1.InitialData3;
begin
Parray[0]:=4; Parray[1]:=3; Parray[2]:=2; Parray[3]:=3;
Parray[4]:=4; Parray[5]:=3; Parray[6]:=5; Parray[7]:=4;
Parray[8]:=3; Parray[9]:=2; Parray[10]:=1; Parray[11]:=5;
Mnum:=3;
PNum:=12;
P1.Text:=IntToStr(Parray[0]); P2.Text:=IntToStr(Parray[1]);
P3.Text:=IntToStr(Parray[2]); P4.Text:=IntToStr(Parray[3]);
P5.Text:=IntToStr(Parray[4]); P6.Text:=IntToStr(Parray[5]);
P7.Text:=IntToStr(Parray[6]); P8.Text:=IntToStr(Parray[7]);
P9.Text:=IntToStr(Parray[8]); P10.Text:=IntToStr(Parray[9]);
P11.Text:=IntToStr(Parray[10]); P12.Text:=IntToStr(Parray[11]);
Memery.Text:=IntToStr(Mnum);
RadioButton1.Checked:=true;
RadioButton3.Checked:=true;
end;
procedure TForm1.Fifo_Lru;
var
i,j,k,havenum,flag:integer;
Memory:array[0..30] of integer;
begin
for i:=0 to Mnum-1 do
Memory[i]:=-200;
havenum:=0;
for i:=0 to Pnum-1 do
begin
flag:=0;
for j:=0 to Mnum-1 do
begin
if(Parray[i]=Memory[j]) then//*命中,且内存中有此数*/
begin
ml[30][i]:=-100;//*用-100表示命中*/;
if RadioButton3.Checked=true then
begin
if havenum>=Mnum then
begin
for k:=Mnum-1 downto 1 do
begin
Memory[k]:=Memory[k-1];
ml[k][i]:=Memory[k];
end;
Memory[0]:=Parray[i];
ml[0][i]:=Memory[0];
end
else for k:=0 to Mnum-1 do
ml[k][i]:=Memory[k];
end
else if RadioButton4.Checked=true then
begin
if (j>0) and (j<Mnum-1) then
for k:=0 to j-1 do
Memory[k+1]:=Memory[k];
if j=Mnum-1 then
for K:=Mnum-1 downto 1 do
Memory[k]:=Memory[k-1];
Memory[0]:=Parray[i];
for k:=0 to Mnum-1 do
ml[k][i]:=Memory[k];
end;
flag:=1;
break;
end;//end if
end;//end for
if flag=1 then continue;
if (havenum<Mnum) then //*命中,且内存中没有此数*/
begin
havenum:=havenum+1;
ml[30][i]:=-100;//*用-100表示命中*/;
for k:=Mnum-1 downto 1 do
begin
Memory[k]:=Memory[k-1];
ml[k][i]:=Memory[k];
end;
Memory[0]:=Parray[i];
ml[0][i]:=Memory[0];
end
else//*淘汰出一个数*/
begin
ml[30][i]:=-300;//*用-300表示没命中*/;
for k:=Mnum-1 downto 1 do
begin
Memory[k]:=Memory[k-1];
ml[k][i]:=Memory[k];
end;
Memory[0]:=Parray[i];
ml[0][i]:=Memory[0];
end;//endif
end;//end while
end;
procedure TForm1.printf3;
var
i,j:integer;
r:real;
p:TListColumn;
q:TListItem;
begin
ListView3.Columns.Clear;
ListView3.Items.Clear;
p:=ListView3.Columns.Add;
p.Width:=70;
p.Caption:='时 间';
for i:=1 to Pnum do
begin
p:=ListView3.Columns.Add;
p.Width:=30;
p.Caption:=IntToStr(i);
end;
q:=ListView3.Items.Add;
q.Caption:='页面走向';
for i:=1 to Pnum do
q.SubItems.Add(IntToStr(Parray[i-1]));
for i:=1 to Mnum do
begin
q:=ListView3.Items.Add;
q.Caption:=' M'+IntToStr(i)+' ';
for j:=1 to Pnum do
if ml[i-1][j-1]=-200 then q.SubItems.Add('')
else q.SubItems.Add(IntToStr(ml[i-1][j-1]));
end;
r:=0.0;
q:=ListView3.Items.Add;
q.Caption:=' 命中 ';
for i:=0 to Pnum-1 do
if ml[30][i]=-100 then
begin
q.SubItems.Add('√');
r:=r+1;
end
else if ml[30][i]=-300 then q.SubItems.Add('×');
r:=r/Pnum*100;
Label38.Width:=100;
label38.Caption:=FloatToStr(r)+'%';
end;
function TForm1.TextToInt3:boolean;
var
str,ch:string;
midnum,totalnum,LengthNum,i,j:integer;
startF,NumStartF:boolean;
begin
Mnum:=StrToInt(Memery.Text);
if Mnum>30 then
begin
ShowMessage('本软件规定存内容量不能大于30,所以系统将自动把当前内存容量设为30!');
Mnum:=30;
Memery.Text:='30';
end;
if RadioButton1.Checked=true then
begin
PNum:=12;
Parray[0]:=StrToInt(p1.Text); Parray[1]:=StrToInt(p2.Text); Parray[2]:=StrToInt(p3.Text);
Parray[3]:=StrToInt(p4.Text); Parray[4]:=StrToInt(p5.Text); Parray[5]:=StrToInt(p6.Text);
Parray[6]:=StrToInt(p7.Text); Parray[7]:=StrToInt(p8.Text); Parray[8]:=StrToInt(p9.Text);
Parray[9]:=StrToInt(p10.Text); Parray[10]:=StrToInt(p11.Text); Parray[11]:=StrToInt(p12.Text);
end
else if RadioButton2.Checked=true then
begin
str:=PP.Text;
LengthNum:=Length(str);
startF:=false;
NumStartF:=false;
totalnum:=0;
for i:=1 to LengthNum do
begin
ch:=copy(str,i,1);
if (ch<>' ') and (ch<>'(') and (ch<>')') and (ch<>'0') and (ch<>'1') and (ch<>'2') and
(ch<>'3') and (ch<>'4') and (ch<>'5') and (ch<>'6') and (ch<>'7') and (ch<>'8') and
(ch<>'9') and (ch<>',') then
begin
ShowMessage('输入字符串不符合要求,串中含有非法字符!');
result:=false;
exit;
end;
if ch=' ' then continue;
if (ch='(') and (startF=false) then
begin
startF:=true;
continue;
end
else if (ch='(') and (startF=true) then
begin
ShowMessage('输入字符串不符合要求,"("不能多于一个!');
result:=false;
exit;
end;
if (ch=')') and (i<lengthNum )then
begin
ShowMessage('输入字符串不符合要求!');
result:=false;
exit;
end;
if (NumStartF=false) and (ch=',') then
begin
ShowMessage('输入字符串不符合要求!');
result:=false;
exit;
end;
if (ch=')') or (ch=',') then //一个数结束
begin
NumStartF:=false;
continue;
end;
if (ch<>')') and (ch<>',') then midnum:=StrToInt(ch); //一定为数字
if NumStartF=false then //数字的首位
begin
NumStartf:=true;
totalnum:=totalnum+1;
parray[totalnum-1]:=midnum;
continue;
end;
if (NumStartF=true) and (ch<>',') and (ch<>',') then //数字的中间位
begin
parray[totalnum-1]:=parray[totalnum-1]*10+midnum;
continue;
end;
end; //end for
Pnum:=totalnum;
end;
result:=true;
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
RadioButton1.Checked:=true;
RadioButton2.Checked:=false;
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
RadioButton1.Checked:=false;
RadioButton2.Checked:=true;
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
begin
RadioButton3.Checked:=true;
RadioButton4.Checked:=false;
GroupBox8.Caption:='FIFO';
end;
procedure TForm1.RadioButton4Click(Sender: TObject);
begin
RadioButton4.Checked:=true;
RadioButton3.Checked:=false;
GroupBox8.Caption:='LRU';
end;
procedure TForm1.EClick(Sender: TObject);
begin
close;
end;
procedure TForm1.IntToText1;
begin
//计算Need
N11.Text:=IntToStr(Max[0][0]-allocation[0][0]);
N12.Text:=IntToStr(Max[0][1]-allocation[0][1]);
N13.Text:=IntToStr(Max[0][2]-allocation[0][2]);
N21.Text:=IntToStr(Max[1][0]-allocation[1][0]);
N22.Text:=IntToStr(Max[1][1]-allocation[1][1]);
N23.Text:=IntToStr(Max[1][2]-allocation[1][2]);
N31.Text:=IntToStr(Max[2][0]-allocation[2][0]);
N32.Text:=IntToStr(Max[2][1]-allocation[2][1]);
N33.Text:=IntToStr(Max[2][2]-allocation[2][2]);
N41.Text:=IntToStr(Max[3][0]-allocation[3][0]);
N42.Text:=IntToStr(Max[3][1]-allocation[3][1]);
N43.Text:=IntToStr(Max[3][2]-allocation[3][2]);
N51.Text:=IntToStr(Max[4][0]-allocation[4][0]);
N52.Text:=IntToStr(Max[4][1]-allocation[4][1]);
N53.Text:=IntToStr(Max[4][2]-allocation[4][2]);
end;
procedure TForm1.TextToInt1;
begin
Max[0][0]:=StrToInt(M11.Text); Max[0][1]:=StrToInt(M12.Text); Max[0][2]:=StrToInt(M13.Text);
Max[1][0]:=StrToInt(M21.Text); Max[1][1]:=StrToInt(M22.Text); Max[1][2]:=StrToInt(M23.Text);
Max[2][0]:=StrToInt(M31.Text); Max[2][1]:=StrToInt(M32.Text); Max[2][2]:=StrToInt(M33.Text);
Max[3][0]:=StrToInt(M41.Text); Max[3][1]:=StrToInt(M42.Text); Max[3][2]:=StrToInt(M43.Text);
Max[4][0]:=StrToInt(M51.Text); Max[4][1]:=StrToInt(M52.Text); Max[4][2]:=StrToInt(M53.Text);
allocation[0][0]:=StrToInt(Y11.Text); allocation[0][1]:=StrToInt(Y12.Text); allocation[0][2]:=StrToInt(Y13.Text);
allocation[1][0]:=StrToInt(Y21.Text); allocation[1][1]:=StrToInt(Y22.Text); allocation[1][2]:=StrToInt(Y23.Text);
allocation[2][0]:=StrToInt(Y31.Text); allocation[2][1]:=StrToInt(Y32.Text); allocation[2][2]:=StrToInt(Y33.Text);
allocation[3][0]:=StrToInt(Y41.Text); allocation[3][1]:=StrToInt(Y42.Text); allocation[3][2]:=StrToInt(Y43.Text);
allocation[4][0]:=StrToInt(Y51.Text); allocation[4][1]:=StrToInt(Y52.Text); allocation[4][2]:=StrToInt(Y53.Text);
//计算Need
need[0][0]:=Max[0][0]-allocation[0][0];
need[0][1]:=Max[0][1]-allocation[0][1];
need[0][2]:=Max[0][2]-allocation[0][2];
need[1][0]:=Max[1][0]-allocation[1][0];
need[1][1]:=Max[1][1]-allocation[1][1];
need[1][2]:=Max[1][2]-allocation[1][2];
need[2][0]:=Max[2][0]-allocation[2][0];
need[2][1]:=Max[2][1]-allocation[2][1];
need[2][2]:=Max[2][2]-allocation[2][2];
need[3][0]:=Max[3][0]-allocation[3][0];
need[3][1]:=Max[3][1]-allocation[3][1];
need[3][2]:=Max[3][2]-allocation[3][2];
need[4][0]:=Max[4][0]-allocation[4][0];
need[4][1]:=Max[4][1]-allocation[4][1];
need[4][2]:=Max[4][2]-allocation[4][2];
//available
available[0]:=StrToInt(K11.Text);
available[1]:=StrToInt(K12.Text);
available[2]:=StrToInt(K13.Text);
end;
procedure TForm1.BitBtn6Click(Sender: TObject);
begin
Application.HelpContext(1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -