Dear Alexei, On Sat, 19 Aug 2006, Sheplyakov Alexei wrote:
I don't like adding any virtual methods to GiNaC::basic (actually, I'd like to get rid of some already existing ones). Leaving aside "aesthetical" issues (such an approach is completely anti-OO), adding virtual method costs extra bytes (at least, vtable entry should be stored somewhere) for *every* GiNaC object. With real-world expressions this translates into several hundreds of megabytes of RAM wasted for nothing good.
Also leaving the aesthetical issue asside, I really don't believe this story about RAM usage. It would be incredibly inefficient design on the part of the compiler if it were true. I tested this, using a simple test program with a class and allocating a large array of that class. Adding the first virtual function to a class makes the class a bit larger. After that, adding more of them doesn't increase size anymore and also the memory usage of the program doesn't really become much larger. The point is of course that every object of a class does only store a *pointer* to a table of virtual methods and not the table itself. Such a table only needs to be stored only once for every class declared. Best wishes, Chris