delphi用API复制文件多线程的速度怎么比单线程还慢?
我做了个多线程复制的小工具,用的是CopyFile函数,复制128M的几个视频,但是多线程复制的速度不理想
1个线程复制用了5.5秒
3个线程却用了6.07秒,
复制1.25G的文件
1个线程用了205s
10个线程用了2.6.5s
为什么会这样呢?
各位帮帮忙看下
procedure Copy(); //复制vari: word;begin with MainForm do begin Path := Edit.Text; //path 是个全局的string变量 for i := 0 to FList.Count - 1 do //filelist是储存目标文件路径的stringlist变量 begin if DirectoryExists(Path)then begin if CopyFile(PChar(FList[i]),Pchar(Path +'\'+ ExtractFileName(FList[i])),false) then begin Cs.Enter; //cs是个全局的临界区类 inc(Proc);//d当前进度 StatusBar.Panels[3].Text := Format('进度: %d/%d',[Proc,FileMemo.Lines.Count]); ProgressBar.Position := ProgressBar.Position + 1; RichEdit.Lines.Add('[提示] 文件'+Flist.Strings[i]+'复制成功'); Cs.Leave; Continue; end else begin Cs.Enter; RichEdit.Lines.Add(''); RichEdit.SelStart := Echo.GetTextLen; RichEdit.Text := Format('%s[提示] 文件“%s”复制失败',[Echo.Text,Flist.Strings[i]]); RichEdit.SelLength := Length( Format('[提示] 文件“%s”复制失败',[Flist.Strings[i]])); Echo.SelAttributes.Color := clRed; Cs.Leave; end; end; end; end; Dec(TCount);end;