Skip to main content
GameDev.net gamedev.net
🔒 Locked

static_cast / interface performance

Started by wasd Jun 2, 2006 at 2:38 PM 0 replies 650+ views
Original Post
wasd
wasd
I'm designing an engine which will (hopefully) be as platform independent as possible. I'm on the renderer at the moment, and I'm ending up with having defined interface classes that the external program uses, then having platform dependent classes derrived from these. What it means is that the user's program will have access to things like IIndexBuffer and IVertexBuffer, which can be passed to the renderer then cast by the renderer to its platform dependent CIndexBuffer (using static_cast). My question is, using this method, am I going to be incurring any major performance penalties, seeing as how there'll probably be a lot of these casts each frame (index, vertex buffers, textures, shaders)?
ApochPiQ
ApochPiQ
The big clue to static_cast is the "static" portion. A static cast is validated at compile time, which means that in runtime terms there is literally no overhead to doing a cast. The one to look out for is dynamic_cast which can have fairly significant performance implications if used often.

However, excessive use of casts is usually a strong symptom of poor class design. You might carefully consider altering your design to eliminate the need for such prolific casting.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.