Archived

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

goldsword

virtual functions & abstract classes

Recommended Posts

Hi, I''ve just started a school project of mine where I''m to create a little game. I decided to start my project writing a resource manager, all my resources should be derived from a base resource class. I would like this base class to be a pure virtual function and derive all other resources from it with their own set of Load(), Release() and other functions. I''m also planning on using virtual classes for my game objects, using a base object class and derive all other objects from it. My questions: 1. How slow is virtual functions since they bind on runtime? 2. Should I use a regular approach rather where i give each class a type and use void pointers, or is there a better way? 3. How do you do when managing resources, game objects and other stuff? / Thanks!

Share this post


Link to post
Share on other sites
quote:
Original post by goldsword
1. How slow is virtual functions since they bind on runtime?


No slower(and probably faster) than the mechanism you would have to write to emulate the functionality.

quote:

use void pointers


/me shudders...

quote:

3. How do you do when managing resources, game objects and other stuff?


The question is a bit vague, methinks.


Share this post


Link to post
Share on other sites
quote:
No slower(and probably faster) than the mechanism you would have to write to emulate the functionality.


Not completely true, virtual functions do take slightly more time to call (though not much longer), plus, memory wise, it takes up an extra sizeof(Datatype*) per instance of the class. However, yes, considering you would want to emulate similar functionality using other methods, virtual functions are more likely faster (depending on the alternate method and the number of situations handled), especially when dealing with many varied datatypes.

--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."

Share this post


Link to post
Share on other sites