Old problem with performance

Walter Bright newshound1 at digitalmars.com
Sun Feb 8 11:13:00 PST 2009


Frits van Bommel wrote:
> Which helps (a bit) with the two instances allocated in main(), but is 
> rather unhelpful with the 100_000_000 allocated in opAdd() (they're 
> returned)...

The use of classes in this example is like using a screwdriver as a 
hammer. It'll work in a pinch, but a hammer works a lot better. If 
you're allocating 100_000_000 classes in a tight loop, some refactoring 
looks to be in order.

In particular, classes are *meant* to be used as reference types, but 
the program is trying to treat them as value types. Virtual functions 
are orthogonal to what value types are - a continuing problem C++ 
programs have is conflating value types with reference types.



More information about the Digitalmars-d mailing list