Jump to content
  • Advertisement
Sign in to follow this  
Keisni

How to know an inline function is really inline

This topic is 4034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You can't 'truly' know unless you look at the generated assembly and see how it is called and appears in the target. If you need help figuring it out though in ASM, you could use something like:


__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }
// function body goes here
__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }


What that does is pad 5 NOPs around the body of the code (but will still come after prolog and end before epilog code, reference) but you can open up a free disassembler, OlylDbg for example, and use the search command for 5 NOPS in a row and see where your code is. **

The only caveat to that is the compiler might optimize out certain things like that, but I am not sure. When going between debug and release configurations the code is different anyways so no telling if this is actually will work.

** The above is not truly tested against identifying inline code and is just an idea.

Share this post


Link to post
Share on other sites
You could try putting a breakpoint on the line calling your function. When you run the app, you arrive at the breakpoint and tracing into the function does not actually get you into the code of that function it most probably is inlined.

But the best way is by looking at the generated code. It really isnt hard you know. Just put a breakpoint, run, right-click, get "show disassembly" and look if you see a "call ...." towards your function. If there is one, the function isnt inlined.

(all of the above was written with Visual C++ in mind as IDE ;) )

Share this post


Link to post
Share on other sites
Quote:
Original post by Keisni
Is there a simply method? (without knowledge of dasm)

Without looking at the assembly, I don't think you can. C++ doesn't have any way to guarantee that a function is inlined. The compiler can ignore the inline keyword if it wants to.

Share this post


Link to post
Share on other sites
Some compilers also provide the "__forceinline" keyword (MSVC does) but, once again, I'm not sure if it's 100% garanteed to come out inlined.

Share this post


Link to post
Share on other sites
TBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
TBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.


Some compilers, like Visual C++, can sometimes inline functions that are not declared as inline through whole program optimization and link time code generation. In general though if you have a function that is a good candidate for inlining (generally a short and simple function that you know is called with high frequency in performance sensitive code) then it is worth declaring it as inline and defining it in a header where it is visible to all callers as the optimizer is more likely to be able to inline it where appropriate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!