Hi Watson,

On 9/1/06, Watson Ladd <[EMAIL PROTECTED]> wrote:
How does inheritance bloat a class?

Overall memory footprint might not be bloated but that not what critical, its down to the CPU requiring different chunks of memory from the data structure to do its job, if the data for each task it does it spread widely then they will be an excessive number of cache misses.  If you keep all the associated data that it'll need close together then you win.

Inheritance can increase the spread that different key component are position at in the data structure, for instance osg::Object has things like name, user data and data variance, and osg::Referenced has its reference count and mutex pointer, these will all sit at the top of any OSG object, along with the virtual table pointer. 

Now when traversing the scene the processor will have to read the virtual table pointer so that it can find the virtual functions that it requires to call, then it'll look at the data of the object but rarely will it look at osg::Referenced, and rarely will it check the UserData or name or data variance of osg::Object, so in reading in the block with the virtual table it's unlikely to get much of what it'll be interested in next since the cache line is taken up with this redundent stuff (at least redundent for most work done on the scene graph.)

In the case of a scene graph you are traversing through it every frame, doing quick cull tests on nodes and then moving on to its children, or back to its parent.  You burn through tons of memory very quickly, and as consequence its memory performance which is most ciritical.  Optimizing things like matrix maths  and string is typically far less important.

Oh, more than anyting having a efficient well balanced scene graph is the most crucial part of performance with a scene graph, all the above issues are far less critical - i.e. employ various general code optimization and you might get 10-20% improvement, perhaps 100% is certain code segments, but optimize a previously poorly conditioned scene graph and you can easily go improve things by 1000%.  So its important to understand where you'll get the most bang for your buck when it comes to optimization work.

Robert
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to