Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

shaobohou

multiple inheritance as interface

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I been implementing an series of ODE integrator for a game I''ve been working on with some friends. Personally I don''t want the integrator object to know about the objects it is integrating for, more than absolutely necessary, thus the physics object inherit from another class called integratable which has a pure virtual function called derive (provide the derivative of the vector elements) and no data members. This is basically how java does their interface but I was wondering what are the performance cost of the two and whether will the multiple inheritance be too expensive to use for this purpose?

Share this post


Link to post
Share on other sites
Advertisement
How expensive this is would be compiler as well as usage dependent. Most implementations of multiple inheritance work by aggregating separate copies of base objects as "members" of the derived objects and adding either a base object offset to entries in the vtable or directing vtable entries to a thunk. If you use simple interface style abstract classes as base classes, this usually just adds an extra vtable pointer to the derived class. The overhead in the vtable would be paid no matter if it was a single or multiple inheritance. So, on the whole, it''s not all that expensive in the base case.

On the other hand, if every class is derived from twenty different interfaces, then you might start running into some performance problems.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by SiCrane
Most implementations of multiple inheritance work by aggregating separate copies of base objects as "members" of the derived objects and adding either a base object offset to entries in the vtable or directing vtable entries to a thunk.


No implementation aggregates the separate copies of base objects by default. You must mark a base class as virtual for it to be aggregated in multiple inheritence; otherwise, each base gets its own copy of any common base class. I''d suggest reading "The C++ Object Model". There''s many ways that the object model could be implemented; however, most compilers today are very close to the model specified in this book.

Share this post


Link to post
Share on other sites
I think you misunderstood my statement. I said "separate copies of base objects" not "a separate object for every base class in the hierarchy", which seems how you interpreted my remark. If anything a complaint should be leveraged in the opposite direction because my statement deliberately ignored virtual inheritance (which seemed irrelevant to the question at hand).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!