gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Wrapping functions and performance

#170494 - Rajveer - Tue Sep 29, 2009 5:21 pm

Does wrapping an existing function and declaring it as inline have any performance hit? E.g. In the following example, would w_actualFunction be any slower than calling actualFunction itself? I'm assuming not as the compiler would replace any call to w_actualFunction with actualFunction as the first is inlined, but is that it or is there anything behind the scenes that may hinder performance?

Code:
inline int w_actualFunction(int variable)
{
actualFunction(variable);
}

int actualFunction(int variable)
{
...
..
...
}


I want to wrap all libnds GL functions so I can compile my code for Windows or the DS, with the DS wrappers simply calling the actual libnds function and the PC wrappers using "proper" OpenGL or doing nothing at all.

#170496 - Miked0801 - Tue Sep 29, 2009 6:22 pm

I see no classes and as long as the wrapper does nothing and the compiler decides to listen to your inline directive, then it should be fine.

#170513 - Rajveer - Wed Sep 30, 2009 12:06 am

Thanks, yeah that's pretty much all the wrapper on the DS side will be. I've read on a forum post that using -finline-functions will force inline-functions to be inlined?

On another note I've been reading up on inline functions, particularly in C99, and read that by using static inline you don't need to provide an extern definition of the inlined function in a separate source file (which you don't need to do in C++ anyways). Is this why all inlined functions in libnds are static inlined?

#170533 - sajiimori - Thu Oct 01, 2009 2:32 am

As far as I know, the only difference between "inline" and "static inline" is that for non-static inlines, the compiler will additionally generate a non-inlined version of the function, which will be used anytime the inline version can't be used for any reason.

At link time, if it turns out that the non-inlined version is never used, then it would normally be dead stripped... but dead stripping is not GCC's strong suit, so it's worth checking the memory map to see if it contains redundant functions.

Anyway, a lot of the specifics are implementation dependent. I always declare my inline non-member functions as static, but maybe on some implementations that'll result in multiple copies of the non-inlined function -- one copy for each module where it fails to inline for whatever reason.

My only other tip would be to never assume that inlining will work 100% of the time.

#170698 - Rajveer - Tue Oct 13, 2009 12:40 am

Bit late, but thanks for that informative explanation :)

#178300 - sajjad123 - Sun Dec 14, 2014 4:49 am

As far as I know, the only difference between "inline" and "static inline" is that for non-static inlines, the compiler will additionally generate a non-inlined version of the function, which will be used anytime the inline version can't be used for any reason.

___________________________
Are you interested in 350-029 - testking Get our self paced testking 642-437 - braindumps - questions and Florida Memorial University study packages to pass your Keiser University without any difficulty in Northwood University.


Last edited by sajjad123 on Tue Dec 23, 2014 8:45 am; edited 1 time in total

#178301 - Dwedit - Sun Dec 14, 2014 5:59 pm

sajjad123 wrote:
As far as I know, the only difference between "inline" and "static inline" is that for non-static inlines, the compiler will additionally generate a non-inlined version of the function, which will be used anytime the inline version can't be used for any reason.

Necrobump spam repeating a previous post
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#178302 - Rajveer - Mon Dec 15, 2014 10:59 am

Oh man these bots are just getting lazy now XD