[fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
prof7bit at googlemail.com
Thu Jul 28 18:59:34 CEST 2011
2011/7/28 Bernd <prof7bit at googlemail.com>:
> I have tried making
> use of Interface and TInterfacedObject and this seems to do what I
> want: for example when witing A := A + B the + operator would return a
> new instance and the reference counting would then automatically call
> the destructor of A when it assigns the newly created number.
I have profiled it
procedure Loop(a,b: IFoo);
I : Integer;
for i := 0 to 10000 do begin
//BN_mul(b.Handle, a.Handle, a.Handle, b.Context);
b := a * a;
This creates and destroys an object of TFoo everytime and this in turn
will also create and free resources inside OpenSSL, its only spending
37% of the time doing actually useful work (BN_mul).
I think I'm not going to continue this route. I can't see any possible
way to make useful use of overloading these operators, other than
making a few lines in other places of the code look a little bit nicer
at the cost of degrading performance by a factor of 3 (for add instead
of mul its even factor 6).
Occasionally I hear other people mentioning operator overloading as a
must-have feature of any decent language but I wonder what real-world
problems they are actually solving with it. Are other compilers better
at dealing with these problems, is there room for improvement?
More information about the fpc-pascal