各位大虾帮我看看这个报错是什么问题,
源码是为了演示操作系统可变分区实验(囊中空空,不好意思)
其中listbox1只作演示使用,大虾给个建议用那个控件更为合适。unit Memory01;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math, Strutils, ExtCtrls;const M = 10;
N = 10;
Min = 100; //最小分配大小
type
AMem = record
name : array[0..10] of char;
address : integer;
size : integer;
flag : integer;
//1:used,0:no have
end; RMem = record
address : integer;
size : integer;
flag : integer;
//1:empty , 0:nohave
end;type
TForm6 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
StaticText1: TStaticText;
StaticText2: TStaticText;
Button4: TButton;
StaticText3: TStaticText;
Bevel1: TBevel;
ListBox1: TListBox; procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
function allocate( name : pchar ; size : integer):Boolean;
function reclaim( name : pchar):Boolean;
procedure ini();
{ Private declarations }
public
{ Public declarations }
end;var
Form6: TForm6;
aamem : array[0..M] of AMem ;
rrmem : array[0..N] of RMem ;implementation{$R *.dfm}uses MainForm;procedure ini();
var i : integer;
begin
rrmem[0].address := 0;
rrmem[0].size := 10000;
rrmem[0].flag := 1;
for i := 1 to M-1 do
begin
rrmem[i].flag:=0;end;
for i := 0 to N-1 do
begin
aamem[i].flag:=0;end;
end;//optimization fit arithmetic
function allocate(name : pchar ; size : integer):Boolean;
var i,j,min,trackr,tracka,sum : integer;
begin
i := 0;
j := 0;
trackr := -1;
tracka := -1;
sum := 0;
//search the first empty node from allocate\'s table
repeat
if aamem[j].flag = 0 then
begin
tracka := j;
break;
end;
inc(j);
until j>=M ;
j := 0;
//search endif tracka = -1 then
result := false;//search the first empty node from reclaim\'s table
repeat
if rrmem[i].flag = 1 then
begin
trackr := i;
break;
end;
inc(i);
until i>=M ;
i := 0;
//seache end//account how many empty block of memory
j:=0;
repeat
if rrmem[j].flag = 1 then
inc(sum);
inc(j);
until j>=M ;
if sum = 0 then
result := false;
//account end//seek whether enough have a block memory
//if not return false
j := 0;
repeat
if rrmem[j].flag = 1 then
if rrmem[j].size < size then
inc(j)
else
break;
until j >= sum ;
if j = sum then
result := false;
//end seekmin := Abs(size - rrmem[i].size);
repeat
inc(i);
if rrmem[i].flag = 1 then
if min<abs(size - rrmem[i].size) then
trackr := i;
until i>=M ;
i := 0;//if not found the fitting node
if trackr = -1 then
result := false
else
begin
//change the reclaim\'s table
//if the apply size less than Min(100)
if size <= Min then
begin
rrmem[trackr].flag := 1; aamem[tracka].address := rrmem[trackr].address;
//change the address of reclaim\'s table
//advert the position
rrmem[trackr].address := rrmem[trackr].address + size;
rrmem[trackr].size := Abs(rrmem[trackr].size-size); //change the allcoate\'s table start
StrCopy(aamem[trackr].name, name);
aamem[tracka].flag := 1;
aamem[tracka].size := size;
//change the allcoate\'s table end
result := true;
end else
begin
//change the reclaim\'s table start
rrmem[trackr].flag:= 1; //change the address of reclaim\'s table
//advert the position
aamem[tracka].address:= rrmem[trackr].address;
//change the address of reclam\'s table end rrmem[trackr].address := rrmem[trackr].address + size;
rrmem[trackr].size:= Abs(rrmem[trackr].size - size);
//change the reclaim\'s table end //change the allocate\'s table start
Strcopy(aamem[tracka].name, name);
aamem[tracka].flag := 1;
aamem[tracka].size := size;
//change the allocate\'s table end
result := true;
end;
end;
end;function reclaim( name : pchar):Boolean;
var tag : Boolean;
i : integer;
tracka : integer;
begin
tag := false;
i := 0;
tracka := -1;
//search the node of want to reclaim
repeat
if aamem[i].flag = 1 then
begin
if not StrComp(aamem[i].name, name) = 0 then
begin
tracka := i;
break;
end;
end;
inc(i);
until i >= M;
//if didn\'t find. return false
if tracka = -1 then
result := false;//if up and down have no empty block memory
if (aamem[tracka-1].flag = 1) and (aamem[tracka+1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 1; tag := true;
end;//if up have empty block memory
if (aamem[tracka-1].flag = 0) and (aamem[tracka+1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka-1].size := rrmem[tracka-1].size+aamem[tracka].size;
rrmem[tracka].flag := 1;
rrmem[tracka].size := 0; tag := true;
end;//if down have empty block memory
if (aamem[tracka+1].flag = 0) and (aamem[tracka-1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 1;
rrmem[tracka].size := rrmem[tracka].size+rrmem[tracka+1].size;
rrmem[tracka+1].size := 0; tag := true;
end;//if down and up both have the empty block memory
if (aamem[tracka+1].flag = 0) and (aamem[tracka-1].flag = 0) then
begin
//change the table of allcocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 0;
rrmem[tracka-1].size := rrmem[tracka-1].size+rrmem[tracka].size+rrmem[tracka].size;
rrmem[tracka].size := 0;
rrmem[tracka+1].size := 0; tag := true;
end;
result := tag;
end;procedure TForm6.Button4Click(Sender: TObject);
begin
Edit1.Text := '';
Edit2.Text := '';
ComboBox1.Text := '';
ListBox1.Items.Clear;
close;
Form1.Visible := true;
end;procedure TForm6.Button1Click(Sender: TObject);
var name : string;
size : integer;
ok : Boolean;
begin
name := Edit1.Text;
size :=StrToInt(Edit2.text);
ok := allocate(pchar(name),size);
if ok then
begin
ShowMessage('allcoate successful!');
ComboBox1.AddItem(name,nil);
end
else begin
ShowMessage('allocate unsuccessful!');
break;
end;
end;procedure TForm6.Button2Click(Sender: TObject);
var name : array[0..10] of Char;
ok : Boolean;
begin
name := pchar(ComboBox1.text);
ok := reclaim(name);
if ok then
begin
ShowMessage('reclaim is successful!');
ComboBox1.DeleteSelected;
end
else begin
Showmessage('reclaim is unsucssful!');
break;
end;
end;procedure TForm6.Button3Click(Sender: TObject);
var s1,s2,s3 : string;
i : integer;begin
s1 := 'About Infomation:';
ListBox1.AddItem(s1,nil);
s2 := 'Process name Start address Size' ;
ListBox1.AddItem(s2,nil);
for i := 0 to M-1 do
begin
if aamem[i].flag = 1 then
begin
s3 :=aamem[i].name+' '+IntToStr(aamem[i].address)+' '+IntToStr(aamem[i].size) ;
ListBox1.AddItem(s3,nil);
end;
end;
end;end.
源码是为了演示操作系统可变分区实验(囊中空空,不好意思)
其中listbox1只作演示使用,大虾给个建议用那个控件更为合适。unit Memory01;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math, Strutils, ExtCtrls;const M = 10;
N = 10;
Min = 100; //最小分配大小
type
AMem = record
name : array[0..10] of char;
address : integer;
size : integer;
flag : integer;
//1:used,0:no have
end; RMem = record
address : integer;
size : integer;
flag : integer;
//1:empty , 0:nohave
end;type
TForm6 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
StaticText1: TStaticText;
StaticText2: TStaticText;
Button4: TButton;
StaticText3: TStaticText;
Bevel1: TBevel;
ListBox1: TListBox; procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
function allocate( name : pchar ; size : integer):Boolean;
function reclaim( name : pchar):Boolean;
procedure ini();
{ Private declarations }
public
{ Public declarations }
end;var
Form6: TForm6;
aamem : array[0..M] of AMem ;
rrmem : array[0..N] of RMem ;implementation{$R *.dfm}uses MainForm;procedure ini();
var i : integer;
begin
rrmem[0].address := 0;
rrmem[0].size := 10000;
rrmem[0].flag := 1;
for i := 1 to M-1 do
begin
rrmem[i].flag:=0;end;
for i := 0 to N-1 do
begin
aamem[i].flag:=0;end;
end;//optimization fit arithmetic
function allocate(name : pchar ; size : integer):Boolean;
var i,j,min,trackr,tracka,sum : integer;
begin
i := 0;
j := 0;
trackr := -1;
tracka := -1;
sum := 0;
//search the first empty node from allocate\'s table
repeat
if aamem[j].flag = 0 then
begin
tracka := j;
break;
end;
inc(j);
until j>=M ;
j := 0;
//search endif tracka = -1 then
result := false;//search the first empty node from reclaim\'s table
repeat
if rrmem[i].flag = 1 then
begin
trackr := i;
break;
end;
inc(i);
until i>=M ;
i := 0;
//seache end//account how many empty block of memory
j:=0;
repeat
if rrmem[j].flag = 1 then
inc(sum);
inc(j);
until j>=M ;
if sum = 0 then
result := false;
//account end//seek whether enough have a block memory
//if not return false
j := 0;
repeat
if rrmem[j].flag = 1 then
if rrmem[j].size < size then
inc(j)
else
break;
until j >= sum ;
if j = sum then
result := false;
//end seekmin := Abs(size - rrmem[i].size);
repeat
inc(i);
if rrmem[i].flag = 1 then
if min<abs(size - rrmem[i].size) then
trackr := i;
until i>=M ;
i := 0;//if not found the fitting node
if trackr = -1 then
result := false
else
begin
//change the reclaim\'s table
//if the apply size less than Min(100)
if size <= Min then
begin
rrmem[trackr].flag := 1; aamem[tracka].address := rrmem[trackr].address;
//change the address of reclaim\'s table
//advert the position
rrmem[trackr].address := rrmem[trackr].address + size;
rrmem[trackr].size := Abs(rrmem[trackr].size-size); //change the allcoate\'s table start
StrCopy(aamem[trackr].name, name);
aamem[tracka].flag := 1;
aamem[tracka].size := size;
//change the allcoate\'s table end
result := true;
end else
begin
//change the reclaim\'s table start
rrmem[trackr].flag:= 1; //change the address of reclaim\'s table
//advert the position
aamem[tracka].address:= rrmem[trackr].address;
//change the address of reclam\'s table end rrmem[trackr].address := rrmem[trackr].address + size;
rrmem[trackr].size:= Abs(rrmem[trackr].size - size);
//change the reclaim\'s table end //change the allocate\'s table start
Strcopy(aamem[tracka].name, name);
aamem[tracka].flag := 1;
aamem[tracka].size := size;
//change the allocate\'s table end
result := true;
end;
end;
end;function reclaim( name : pchar):Boolean;
var tag : Boolean;
i : integer;
tracka : integer;
begin
tag := false;
i := 0;
tracka := -1;
//search the node of want to reclaim
repeat
if aamem[i].flag = 1 then
begin
if not StrComp(aamem[i].name, name) = 0 then
begin
tracka := i;
break;
end;
end;
inc(i);
until i >= M;
//if didn\'t find. return false
if tracka = -1 then
result := false;//if up and down have no empty block memory
if (aamem[tracka-1].flag = 1) and (aamem[tracka+1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 1; tag := true;
end;//if up have empty block memory
if (aamem[tracka-1].flag = 0) and (aamem[tracka+1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka-1].size := rrmem[tracka-1].size+aamem[tracka].size;
rrmem[tracka].flag := 1;
rrmem[tracka].size := 0; tag := true;
end;//if down have empty block memory
if (aamem[tracka+1].flag = 0) and (aamem[tracka-1].flag = 1) then
begin
//change the table of allocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 1;
rrmem[tracka].size := rrmem[tracka].size+rrmem[tracka+1].size;
rrmem[tracka+1].size := 0; tag := true;
end;//if down and up both have the empty block memory
if (aamem[tracka+1].flag = 0) and (aamem[tracka-1].flag = 0) then
begin
//change the table of allcocate
aamem[tracka].flag := 0;
//change the table of reclaim
rrmem[tracka].flag := 0;
rrmem[tracka-1].size := rrmem[tracka-1].size+rrmem[tracka].size+rrmem[tracka].size;
rrmem[tracka].size := 0;
rrmem[tracka+1].size := 0; tag := true;
end;
result := tag;
end;procedure TForm6.Button4Click(Sender: TObject);
begin
Edit1.Text := '';
Edit2.Text := '';
ComboBox1.Text := '';
ListBox1.Items.Clear;
close;
Form1.Visible := true;
end;procedure TForm6.Button1Click(Sender: TObject);
var name : string;
size : integer;
ok : Boolean;
begin
name := Edit1.Text;
size :=StrToInt(Edit2.text);
ok := allocate(pchar(name),size);
if ok then
begin
ShowMessage('allcoate successful!');
ComboBox1.AddItem(name,nil);
end
else begin
ShowMessage('allocate unsuccessful!');
break;
end;
end;procedure TForm6.Button2Click(Sender: TObject);
var name : array[0..10] of Char;
ok : Boolean;
begin
name := pchar(ComboBox1.text);
ok := reclaim(name);
if ok then
begin
ShowMessage('reclaim is successful!');
ComboBox1.DeleteSelected;
end
else begin
Showmessage('reclaim is unsucssful!');
break;
end;
end;procedure TForm6.Button3Click(Sender: TObject);
var s1,s2,s3 : string;
i : integer;begin
s1 := 'About Infomation:';
ListBox1.AddItem(s1,nil);
s2 := 'Process name Start address Size' ;
ListBox1.AddItem(s2,nil);
for i := 0 to M-1 do
begin
if aamem[i].flag = 1 then
begin
s3 :=aamem[i].name+' '+IntToStr(aamem[i].address)+' '+IntToStr(aamem[i].size) ;
ListBox1.AddItem(s3,nil);
end;
end;
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货