Old problem with performance

Weed resume755 at mail.ru
Mon Feb 9 02:05:40 PST 2009


Kagamin пишет:
> Weed Wrote:
> 
>> The code on C++ is also approximately in 6 times faster a code with
>> classes on D. (I do not give an example on C++ because classes on C++
>> work just as structures in D.)
> 
>> class C {
>>     int i;
>>     real[5] unused; // to prevent returning this object in registers
>>
>>     C opAdd( C src ) {
>>         auto ret = new C;
>>         ret.i = i + src.i;
>>         return ret;
>>     }
>> }
> 
> Well, D class code here is not equivalent to C++ class code. D code has more features, namely, it's polymorphic: C.opAdd is able to work with classes, derived from C, while corresponding C++ code is unable to do so. If you can't use polymorphism, why do you use classes?

There opAdd is only for demonstration. In real life it may be virtual
method getSomething()



More information about the Digitalmars-d mailing list