Пожалуйста, обратите внимание, что пользователь заблокирован
Всем здрасте, понадобилось написать софт который например удалит дубликаты строк в огромном файле 50 гигабайт попробовал TDictionary, THashSet, THashMap для сравнения строк
почему то они очень сильно едят оперативную память может что то неправильно делаю ?
почему то они очень сильно едят оперативную память может что то неправильно делаю ?
Код:
//TDictionary
procedure ReadFl(const myfile:string);
var
sr: TStreamReader;
Writer:TStreamWriter;
Line:string;
StrDictionary: TDictionary<string, Integer>;
begin
StrDictionary := TDictionary<string, Integer>.Create;
Writer := TStreamWriter.Create(ExtractFilePath(paramStr(0)) + 'DupDel.txt', False, TEncoding.Default, 65535);
try
sr := TStreamReader.Create(myfile,TEncoding.Default, True,2048);
while not sr.EndOfStream do
begin
Line:=Trim(sr.ReadLine);
if not StrDictionary.ContainsKey(Line) then begin
StrDictionary.Add(Line, 0);
Writer.WriteLine(Line);
end;
end;
finally
sr.Close;
FreeAndNil(sr);
StrDictionary.Free;
Writer.Close;
Writer.Free;
end;
end;
//HashSet Example
procedure ReadFl2(const myfile:string);
var
sr: TStreamReader;
Writer:TStreamWriter;
Hash:integer;
Line:string;
HashSet:THashSet<integer>;
begin
HashSet := THashSet<Integer>.Create(1000000,nil); //1000000 Capacity, Comparer = nil
Writer := TStreamWriter.Create(ExtractFilePath(paramStr(0)) + 'DupDel.txt', False, TEncoding.Default, 65535);
try
sr := TStreamReader.Create(myfile,TEncoding.Default, True,2048);
while not sr.EndOfStream do
begin
Line:=Trim(sr.ReadLine);
Hash:=TStringComparer.OrdinalIgnoreCase.GetHashCode(Line);;
if not HashSet.Contains(Hash) then begin
HashSet.Add(Hash);
Writer.WriteLine(Line);
end;
end;
finally
sr.Close;
FreeAndNil(sr);
HashSet.Free;
Writer.Close;
Writer.Free;
end;
end;
