Re: [fpc-pascal] File handling: the TFileStream or the classical way is faster and more efficient?

2015-05-25 Thread Michael Van Canneyt



On Mon, 25 May 2015, Géza Kovacs Géza wrote:


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?


TFileStream offers more flexibility, but as far as efficiency is concerned : 
I think that will be the same for both approaches.


For example, your first example can be done easier in a single statement:

OutF.CopyFrom(Inf,0);

Michael.



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-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] File handling: the TFileStream or the classical way is faster and more efficient?

2015-05-25 Thread Géza Kovacs Géza
Hi!

Thx your answer.


Can I use the "AssignFile" procedure from the SysUtils unit instead of
the simple assign procedure from the System unit?
What is the problem with the simple "assign"?

I read from the Free Pascal Wiki:
AssignFile (prevent the use of the older Assign procedure) - Assign a
name to a file

CloseFile (prevent the use of the older Close procedure) - Close opened file

What is the difference between simple "assign", "close", or
"AssignFile", and "CloseFile"?

Best regards, G
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] File handling: the TFileStream or the classical way is faster and more efficient?

2015-05-25 Thread Michael Van Canneyt



On Mon, 25 May 2015, Géza Kovacs Géza wrote:


Hi!

Thx your answer.


Can I use the "AssignFile" procedure from the SysUtils unit instead of
the simple assign procedure from the System unit?
What is the problem with the simple "assign"?

I read from the Free Pascal Wiki:
AssignFile (prevent the use of the older Assign procedure) - Assign a
name to a file

CloseFile (prevent the use of the older Close procedure) - Close opened file

What is the difference between simple "assign", "close", or
"AssignFile", and "CloseFile"?


There is none, they are 100% the same.

There is no reason not to use the Assign/Close in non-gui code.

The (IMHO misguided) reason for these statements is that TPersistent and TForm (a TPersistent descendent) 
have Assign and Close methods. Because of this, confusion can arise if you write Assign or Close in TForm methods.


Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to instantiate a public type in a generic class

2015-05-25 Thread luciano de souza
Sven,

I really thoght that I had replied your message, but now, I realize I
didn't do it.

Actually, the fact compiler does not  support the sintax I proposed,
it's not very severe. In stead of passing a subtype, I can firstly
create a type from the subtype and using it in the specialization:

TPersons = TdgOPFentity.Tentities;

Passing TPersons, the compiler will not complain.

But, say me: is the problem I faced related to 2.4 version? In newer
version, would it be possible to use something like I have proposed or
will the same behviour be maintained?



2015-05-17 15:46 GMT-03:00, luciano de souza :
> Hello listers,
>
> Using Freepascal 2.6.4, I have a problem about generics. In short, I
> can't specialize a class with a subtype of a type declared with
> "public type". Let me try to explain.
>
> In dopf.pas, I have:
>
> type
> generic TdGOpf = class(TdComponent)
> public type
> TEntities = specialize TFPGObjectList
> end;;
>
> If personmapper is a class specialized from TdGOpf, an instance can be
> created as follows:
>
> Personmapper := TPersonMapper.TEntities.create;
>
> Yes, this code is successul. But this code is not:
>
> type
> generic TGAction  = class(specialize TBrookGAction );
> private
> Fentities: t2.TEntities; //Error in type definition
> end;
>
> This code failed, so I tried:
>
> type
> generic TGAction  = class(specialize TBrookGAction );
> public type TCEntities = t2.Tentities; //Error in type definition
> end;
>
> I got also an error if I try:
>
> type
> generic TGAction  = class(specialize TBrookGAction
> );
>
> Well, I think the problem is illustrated. The doubt is how can create
> an instance of a public type, in my case, t2.Tentities inside my
> specialized class?
>
> Best regards,
>
>
> --
> Luciano de Souza
>


-- 
Luciano de Souza
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal