Hi,

Are there any hidden costs to using virtual functions in C++ classes using
the PRC tools? (I know about the GCC compiler and linker switches to disable
exceptions and RTTI.)

I know that polymorphism requires an in-memory table to ensure that the
correct functions get called at run-time (late binding) and that this eats
into the available heap size.  However, I want to use pure virtual functions
in my classes solely to specify a contract that subclasses must abide to. I
will not use base class pointers, only pointers to non-abstract classes.

Example:
-----------------------------------------------
class BaseClass {
    protected:
        int a;
    public:
        virtual void add(int a) = 0;  // Pure virtual function
};

class DerivedClass: public BaseClass {
    public:
        DerivedClass(int a) {
            this->a = a;
        }
        void add(int a); // Implementation omitted
};

BaseClass* a = new DerivedClass(1);
a->add(1); // Polymorphism, late binding
DerivedClass* b = new DerivedClass(1);
b->add(1); // No polymorphism(?), early binding(?)
-----------------------------------------------

I have a gut feeling that the GCC compiler is smart enough to resolve the
function call for "b" at compile-time, hence no need for a function table at
run-time, but I'm not sure. (It's been years since I last used C/C++ for a
large project.)

Also, how much memory does polymorphism actually require? Should you really
avoid it at all costs on Palm OS? My target is OS 3.5+ running on 4Mb+
devices.


Thanks
-Laurens



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to