Jump to content
  • Advertisement
Sign in to follow this  
Silly_con

Unity Inline configuration

This topic is 4906 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

This is a second part of an old post of mine: http://www.gamedev.net/community/forums/topic.asp?topic_id=284673 in which: - one define USING_INLINE that if it's defined make in compiling all members of the class to be inline, and if not defined, all members are non inline. ( Foo.cpp // include .inl file if is defined USING_INLINE Foo.inl // include .h file and have the code of the class members. Foo.h // class declaration, and include the .inl file and the .inc file Foo.inc // have the "parameters" (defined or not defined USING_INLINE) ) what I want to ask now, although it seems stupid, is to get - other define USING_INLINE_BEST, that if USING_INLINE is defined it do nothing, but if USING_INLINE isn't defined, then it only do some functions inline (functions that you have selected before) using the preprocesor #ifdef/ifndef/endif to englobe what functions you want inline. so much preprocesor is a brainbreaker for me, anyone knows or can think a method to do it? thanks

Share this post


Link to post
Share on other sites
Advertisement
This should work for VC++, but you also have to set the correct compiler options.

#if defined( USING_INLINE )

#define INLINE __forceinline // force to be inlined

#elif defined( USING_INLINE_BEST )

#define INLINE // let the compiler choose

#else

#define INLINE __declspec(noinline) // not inlined

#endif


Excerpts from Microsoft docs:

/Ob0 Disables inline expansion, which is on by default.
/Ob1 Expands only functions marked as inline or __inline or, in a C++ member function, defined within a class declaration.
/Ob2 Expands functions marked as inline or __inline and any other function that the compiler chooses (expansion occurs at the compiler's discretion, often referred to as auto-inlining).

The __forceinline keyword overrides the cost/benefit analysis and relies on the judgment of the programmer instead.
The inline keyword tells the compiler that inline expansion is preferred.
__declspec(noinline) tells the compiler to never inline a particular member function (function in a class).


Even with __forceinline, the compiler cannot inline code in all circumstances.

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!