L
liuchong
Unregistered / Unconfirmed
GUEST, unregistred user!
一:
var
S:string;
begin
S:='abc';//此时S的引用计数是多少?
end;
二:
procedure TForm1.btn1Click(Sender: TObject);
var
S:string;
begin
S:='abc';
edt1.Text:=IntToStr(Cardinal(S))+':'+IntToStr(Cardinal(@S[1]));
end;
procedure TForm1.btn2Click(Sender: TObject);
var
S:string;
begin
S:='abc';
edt1.Text:=IntToStr(Cardinal(@S[1]))+':'+IntToStr(Cardinal(S));
end;
这里用到的S[1]为读取操作,会不会改写引用计数?
三:
如果S会改写引用计数,那么下面两段代码怎么会有效率差异:
var
S:string;
I:Cardinal;
begin
S:='';
for I:=1 to 1000000 do
S:=S+'a';
end;
var
S:String;
I:Cardinal;
begin
SetLength(S,1000000);
for I:=1 to 1000000 do
S:='a';
end;
答对者可到下面地址领分:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3327037
var
S:string;
begin
S:='abc';//此时S的引用计数是多少?
end;
二:
procedure TForm1.btn1Click(Sender: TObject);
var
S:string;
begin
S:='abc';
edt1.Text:=IntToStr(Cardinal(S))+':'+IntToStr(Cardinal(@S[1]));
end;
procedure TForm1.btn2Click(Sender: TObject);
var
S:string;
begin
S:='abc';
edt1.Text:=IntToStr(Cardinal(@S[1]))+':'+IntToStr(Cardinal(S));
end;
这里用到的S[1]为读取操作,会不会改写引用计数?
三:
如果S会改写引用计数,那么下面两段代码怎么会有效率差异:
var
S:string;
I:Cardinal;
begin
S:='';
for I:=1 to 1000000 do
S:=S+'a';
end;
var
S:String;
I:Cardinal;
begin
SetLength(S,1000000);
for I:=1 to 1000000 do
S:='a';
end;
答对者可到下面地址领分:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3327037