@@ -68,7 +68,8 @@ TWSThreadBase = class(TThread)
6868
6969 TWSThread = class (TWSThreadBase)
7070 private
71- FBytes: TBytes;
71+ FStartP: Int64;
72+ FEndP: Int64;
7273 FMS: TMemoryStream;
7374 FWSList: TWSList;
7475 procedure UpdateMainHashList ;
@@ -78,7 +79,7 @@ TWSThread = class(TWSThreadBase)
7879 protected
7980 procedure Execute ; override;
8081 public
81- constructor Create(ABytes: TBytes ; AWSManager: TWSManager);
82+ constructor Create(AStartP, AEndP: Int64 ; AWSManager: TWSManager);
8283 destructor Destroy; override;
8384 end ;
8485
@@ -237,23 +238,13 @@ destructor TWSThreadBase.Destroy;
237238end ;
238239
239240{ TWSThread }
240- constructor TWSThread.Create(ABytes: TBytes; AWSManager: TWSManager);
241- var
242- I: Integer;
241+ constructor TWSThread.Create(AStartP, AEndP: Int64; AWSManager: TWSManager);
243242begin
244243 inherited Create(AWSManager);
245- SetLength(FBytes, Length(ABytes)) ;
246- Move(ABytes[ 0 ], FBytes[ 0 ], Length(ABytes)) ;
244+ FStartP := AStartP ;
245+ FEndP := AEndP ;
247246 FStarted := False;
248247 FMS := TMemoryStream.Create;
249- for I := Low(FWSList) to High(FWSList) do
250- begin
251- FWSList[I].FStation := nil ;
252- FWSList[I].FData.FMin := 0 ;
253- FWSList[I].FData.FMax := 0 ;
254- FWSList[I].FData.FTot := 0 ;
255- FWSList[I].FData.FCnt := 0 ;
256- end ;
257248end ;
258249
259250destructor TWSThread.Destroy;
@@ -368,13 +359,29 @@ procedure TWSThread.Execute;
368359 Bytes: TBytes;
369360 BytesEx: TBytes;
370361 Len, LenEx: LongInt;
362+ I: Integer;
363+ FS: TFileStream;
371364begin
372365 UpdateThreadList(utAdd);
373366 try
374367 FStarted := True;
375- FMS.Write(FBytes[0 ], Length(FBytes));
376- FMS.Position := 0 ;
377- FBytes := nil ;
368+ for I := Low(FWSList) to High(FWSList) do
369+ begin
370+ FWSList[I].FStation := nil ;
371+ FWSList[I].FData.FMin := 0 ;
372+ FWSList[I].FData.FMax := 0 ;
373+ FWSList[I].FData.FTot := 0 ;
374+ FWSList[I].FData.FCnt := 0 ;
375+ end ;
376+ FS := TFileStream.Create(FWSManager.FSrcFile, fmOpenRead or fmShareDenyWrite);
377+ try
378+ FS.Position := FStartP;
379+ FMS.SetSize(FEndP - FStartP);
380+ FS.Read(FMS.Memory^, FEndP - FStartP);
381+ FMS.Position := 0 ;
382+ finally
383+ FS.Free;
384+ end ;
378385 Size := 1048576 ;
379386 repeat
380387 Bytes := nil ;
@@ -530,7 +537,7 @@ procedure TWSThreadsWatcher.CreateFinalList;
530537 Min, Max: Double;
531538 Mean: Double;
532539 SL: TStringList;
533- // MS: TMemoryStream;
540+ MS: TMemoryStream;
534541begin
535542 SL := TStringList.Create;
536543 try
@@ -572,56 +579,43 @@ procedure TWSThreadsWatcher.CreateFinalList;
572579 { $ENDIF}
573580
574581 // save to file
575- { MS := TMemoryStream.Create;
582+ MS := TMemoryStream.Create;
576583 try
577584 MS.Write(Pointer(Str)^, Length(Str) div SizeOf(Char));
578585 MS.Position := 0 ;
579586 MS.SaveToFile(' summary.txt' );
580587 finally
581588 MS.Free
582- end;}
589+ end ;
583590end ;
584591
585592procedure TWSThreadsWatcher.Execute ;
586593var
587594 ThreadCnt: Integer;
588- Bytes: TBytes;
589- BytesEx: TBytes;
590595 Size: Int64;
591596 FS: TFileStream;
592- ReadCnt: LongInt;
593- Len, LenEx: LongInt;
594597 WSThread: TWSThread;
598+ StartP, EndP: Int64;
595599begin
596600 FStarted := True;
597601 FS := TFileStream.Create(FWSManager.FSrcFile, fmOpenRead or fmShareDenyNone);
598602 try
599603 Size := Round(FS.Size/(FWSManager.FThreadCnt + 1 ));
600604 FS.Position := 0 ;
605+ StartP := 0 ;
606+ EndP := 0 ;
601607 repeat
602- Bytes := nil ;
603- BytesEx := nil ;
604608 if Size > FS.Size - FS.Position then
605609 Size := FS.Size - FS.Position;
606- SetLength(Bytes, Size);
607- ReadCnt := FS.Read(Bytes[0 ], Size);
608- if (ReadCnt > 0 ) then
609- begin
610- BytesEx := GetNextLineBreak(FS);
611- LenEx := Length(BytesEx);
612- if LenEx > 0 then
613- begin
614- Len := Length(Bytes);
615- SetLength(Bytes, Len + LenEx);
616- Move(BytesEx[0 ], Bytes[Len], LenEx);
617- end ;
618- AddLineBreak(Bytes);
619- WSThread := TWSThread.Create(Bytes, FWSManager);
620- WSThread.Start;
621- while not WSThread.FStarted do
622- Wait(10 );
623- end ;
624- until (ReadCnt = 0 );
610+ if Size > High(LongInt) then
611+ Size := High(LongInt) - 100 ;
612+ StartP := FS.Position;
613+ FS.Position :=FS.Position + Size;
614+ GetNextLineBreak(FS);
615+ EndP := FS.Position;
616+ WSThread := TWSThread.Create(StartP, EndP, FWSManager);
617+ WSThread.Start;
618+ until (FS.Position >= FS.Size);
625619 finally
626620 FS.Free
627621 end ;
0 commit comments