Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

making virtual function inline

Started by Buzz1982 Sep 12, 2004 at 7:05 AM 1 replies 1.1k views
Original Post
Buzz1982
Buzz1982
Hi, can we make a virtual function inline? also what are the conditions when compiler ignores the inline keyword & does not make the functions inline? Thanx a lot bye
s_p_oneil
s_p_oneil
Virtual functions can't be inline because they are always called via a function pointer, and a function pointer must point to a real function.

The compiler generally ignores the inline keyword when it thinks it's smarter than you about optimizations, which is often (it often actually is smarter, but not always). Each compiler is different, but they tend to ignore it for functions over a certain size, recursive functions, and inline functions that call each other too many times (causing the inline expansion to build up to be over that certain size).

If you're using the Microsoft compiler, pull up the help on #pragma, and look at auto_inline, inline_depth, and inline_recursion.
snk_kid
snk_kid
Quote:
Original post by Buzz1982
can we make a virtual function inline?


yes you can always indiciate to the compiler to try and inline.

Quote:
Original post by Buzz1982
also what are the conditions when compiler ignores the inline keyword & does not make the functions inline?


probably non-trivial cases which probably means most of the time but its context & implemenation dependant.

Really thou if your member function is trivial and its something like an accessor method i don't see why it needs to be overridable by sub-types.

If this isn't the case then i wouldn't worry about it so much if it can't be inlined then the overhead probably isn't as bad as you may think it to be, just that one level of indirection is proabably worth 1000 times more than that little performance you lose in terms of flexiablity.

Topic Locked

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

Sign in to reply to this topic.