在後:Copy sublist from list已經止住瞭解釋我的副本列表中的一個子表需要複製單個元素這樣做:複製動態數組塊
for iIndex2 := 0 to MyList.Last.Count-1 do
MySubList.Add(MyList.Last[iIndex2]);
我已驗證的元素的副本,此方法列表中最高的要花費很多時間,一些女性也是如此。試圖用相同的條件模擬靜態數組我需要幾毫秒,一次複製數組中的所有子列表,而不是單個元素。 只是爲了更好地解釋,我有:
program Test_with_array_static;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Generics.Collections;
type
TMyArray = array [1..10] of Integer;
TMyList = TList<TMyArray>;
var
MyArray: TMyArray;
MyList: TMyList;
iIndex1, iIndex2: Integer;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
MyList := TList<TMyArray>.Create;
try
for iIndex1 := 1 to 10 do
begin
if MyList.Count <> 0 then MyArray := MyList.Last;
MyArray[iIndex1] := iIndex1;
MyList.Add(MyArray);
end;
for iIndex1 := 0 to Pred(MyList.Count) do
begin
for iIndex2 := 1 to 10 do Write(MyList[iIndex1][iIndex2]:3);
Writeln;
end;
finally
MyList.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
所以我必須鑫卡特使用未列爲子表,但陣列等工作,但對我來說,我不一般知道有多少是在數組元素和需要動態數組。 我已經改變了代碼:
program Test_with_array_dynamic;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Generics.Collections;
type
TMyArray = array of Integer;
TMyList = TList<TMyArray>;
var
MyArray: TMyArray;
MyList: TMyList;
iIndex1, iIndex2: Integer;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
MyList := TList<TMyArray>.Create;
try
SetLength(MyArray, 10);
for iIndex1 := 1 to 10 do
begin
if MyList.Count <> 0 then MyArray := MyList.Last;
MyArray[iIndex1] := iIndex1;
MyList.Add(MyArray);
end;
for iIndex1 := 0 to Pred(MyList.Count) do
begin
for iIndex2 := 1 to 10 do Write(MyList[iIndex1][iIndex2]:3);
Writeln;
end;
finally
MyList.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
等等,我再有之前的問題;當然,改變這一行:
if MyList.Count <> 0 then MyArray := MyList.Last;
在拷貝單個元素的模式
,所有的工作。 現在我問,如果真的不可能一次複製一個數組,而沒有爲單個元素做一個副本,我只需要它的速度問題。時間非常重要。 非常感謝所有能解決我這個問題的人。再次感謝。
我無法理解這一點。哪幾位代碼需要幾分鐘時間,哪一個代碼需要幾毫秒? – 2012-02-23 10:40:55
大衛您好,如果我嘗試從列表中複製單個元素到其他元素,超過1000000個元素的列表(這是我的情況,關於統計信息calc),它也需要很多時間,也需要很長的時間。如果我將數組作爲列表的地方,則需要幾毫秒。在這種情況下列表的問題是隻有當我複製單個元素;除此之外,兩者的時間「相同」(在意義上非常相似)。如果你想,我試着重現它,併發布兩種情況下的代碼。只要告訴我是否需要發佈廣告回答,或者只是添加到原始文章,這是我的疑問。再次感謝。 – 2012-02-23 11:49:45