[fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances

Florian Klämpfl florian at freepascal.org
Sat Jul 30 21:35:08 CEST 2011


Am 30.07.2011 19:27, schrieb Bernd:
> 2011/7/30 Florian Klaempfl <florian at freepascal.org>:
> 
>> The automatic constructor/destructor concept of C++ causes the same
>> overhead. And the overhead for a function or operator overloading based
>> approach is the same imo. Or do you have any example where a function
>> based approach performs better? Overloaded operators are converted into
>> function calls, there is no real difference.
> 
> I didn't intend to mean it is better solved in C++ (or any other
> language), I didn't want to specifically criticize the Operator
> overloading how it is implemented in Object Pascal, I just spent some
> time experimenting with trying to wrap this bignum library in some
> clever way to make it look and behave nicely. I posted this thread
> only because at some point I realized that whatever I do to make it
> behave like a built in type it becomes slow and ineffective and the
> wrapper becomes big and complicated.
> 
> The reason is because it IS a function call.
> 
> A := B + C;
> 
> A := add(B, C);
> 
> This will create a new A and free the old one. I have no idea how to
> prevent this.
> 
> add(A, B, C);
> 
> with var or out arguments would enable me to re-use the existing A.

This is exactly what ref. counting solves? Did you read my other mail
regarding your problem with ref. counting?



More information about the fpc-pascal mailing list