Advantages / Disadvantages of Inheritance, Composition and Several Member Variables

I look at Ogre3D code and WildMagic code, and I found that both deal with their main classes a little differently. As I create my own kernel, I was wondering which one would be best practice and could potentially be better in terms of resources.

There is a Matrix class in WildMagic that inherits the Table class (non-polymorphic). The table class can have N rows and N columns and gets getters and setters for columns and rows. The Matrix class then has functionality that makes sense only for the matrix and conveniently inherits it from the table. In this case, the vector can also inherit from the table (although WildMagic does not). WildMagic also has a Transform object that stores local and derived transformations for Node. Thus, Node will have two Transform objects that contain the necessary transformations (including position, rotation, scale).

In Ogre3D, on the other hand, the Matrix class does not work from anything, and the Ogre3D Node has variables for storing local and derived positions: Vector localPos; Vector derPos; Matrix localRot; Matrix derRot; etc.

Now keep in mind that these are the main objects that will be used / updated / changed thousands of times per frame, and itโ€™s quite difficult to change them if you understand that you have a performance bottleneck on the road when you have a full game, relying on these core classes.

So now the questions are:

  • Is there any cost associated with the Matrix class inheriting the Table class versus the Matrix class, which does everything in the first place
  • Is there a cost associated with having 3 instances of the Transform object in the Node class versus representing the underlying data types via member variables (I understand that in both cases it is composition, there is just one wrapperfor transformations in one case , while in the other case there are transformations are exposed directly.Probably the question can be rephrased:Does a wrapper have a cost (considering it is an object that needs to be created and destroyed)?
  • , , ( ). ?
+3
3

, , . , , , , , , .

1) , . , , , : http://www.hackcraft.net/cpp/templateInheritance/

2) , , . " " , . , .

3) , , . , , .

, . , .

+2

, . . - . , OGRE3D - .

0

(1), , ? , . , , , , , . , - , , , .

In relation to (2), it all comes down to how likely it is that the code should be optimized. As a rule, if the corresponding functions are easily integrated, in the case of a lightweight shell there will not be many actual function calls. But then again, there may be consequences for things like memory layout. It is difficult to predict abstractly.

For (3) I did not make a choice, so I donโ€™t know what you are talking about :-P

0
source

All Articles