Géza Kovacs Géza
2015-05-25 04:42:39 UTC
Hi All!
What is the faster and more efficient, using the TFileStream or the
classical way ("file of byte", or "file") type with
blockread/blockwrite and the other well-know procedures?
What is the better, faster on large files?
See the two example code below.
Program FileCopy_stream;
{$mode objfpc} {$H+}
uses classes,SysUtils;
var
BytesRead,TotalBytesRead : Int64;
puffer : array [1..1048576] of byte;
InF, OutF : TFileStream;
begin
TotalBytesRead := 0;
BytesRead := 0;
try
InF:= TFileStream.Create(ParamSTR(1),fmOpenRead);
OutF := TFileStream.Create(ParamSTR(2),fmCreate);
repeat
BytesRead := InF.Read(puffer,sizeof(puffer));
inc(TotalBytesRead, BytesRead);
OutF.Write(puffer,BytesRead);
until (TotalBytesRead = InF.size);
finally
FreeAndNil(InF);
FreeAndNil(OutF);
end;
end.
Program FileCopy_Classic;
{$mode objfpc} {$H+}
var
NumRead, NumWritten : LongInt;
puffer : array [1..1048576] of byte;
InF,OutF : file of byte;
begin
assign(InF,ParamStr(1));
ReSet(InF);
Assign(OutF,ParamStr(2));
ReWrite(OutF);
repeat
BlockRead(InF,puffer,SizeOf(puffer),NumRead);
BlockWrite(OutF,puffer,NumRead,NumWritten);
until (NumRead = 0);
close(InF);
close(OutF);
end.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
What is the faster and more efficient, using the TFileStream or the
classical way ("file of byte", or "file") type with
blockread/blockwrite and the other well-know procedures?
What is the better, faster on large files?
See the two example code below.
Program FileCopy_stream;
{$mode objfpc} {$H+}
uses classes,SysUtils;
var
BytesRead,TotalBytesRead : Int64;
puffer : array [1..1048576] of byte;
InF, OutF : TFileStream;
begin
TotalBytesRead := 0;
BytesRead := 0;
try
InF:= TFileStream.Create(ParamSTR(1),fmOpenRead);
OutF := TFileStream.Create(ParamSTR(2),fmCreate);
repeat
BytesRead := InF.Read(puffer,sizeof(puffer));
inc(TotalBytesRead, BytesRead);
OutF.Write(puffer,BytesRead);
until (TotalBytesRead = InF.size);
finally
FreeAndNil(InF);
FreeAndNil(OutF);
end;
end.
Program FileCopy_Classic;
{$mode objfpc} {$H+}
var
NumRead, NumWritten : LongInt;
puffer : array [1..1048576] of byte;
InF,OutF : file of byte;
begin
assign(InF,ParamStr(1));
ReSet(InF);
Assign(OutF,ParamStr(2));
ReWrite(OutF);
repeat
BlockRead(InF,puffer,SizeOf(puffer),NumRead);
BlockWrite(OutF,puffer,NumRead,NumWritten);
until (NumRead = 0);
close(InF);
close(OutF);
end.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal