## Recommended Posts

I have a function that just gets a value in a scoll bar as to where the scroll knob is... this is called alot, so it would be called thousands of times in a short time (couple seconds), would it be wise to inline this or should i just do it normally?
int GetValue() { return cpri_Value_I; }

or

int GetValue()
{
return cpri_Value_I;
}


Jake

##### Share on other sites
if the function is very small or if the compiler can optimize it because it knows the input/output parameters beforehand (in case of constants), then it certainly makes sense to inline it.

The best way to find out, however, is to try both while profiling your code :)

Edit: both functions you posted will do the same. You should add 'inline' to one of the functions. Also make sure you put those functions in your header file if it's a global function (or use .inl files).

##### Share on other sites
In general profilers are very good at telling you what code you should inline that you didn't and not so good at telling you what code you shouldn't inline that you did, so I usually recommend not to inline your functions until the profiler says you should.

##### Share on other sites
Just a notice:
Maybe you are aware of this, but the two examples you posted are both NOT inlined.
Inlined would be:

inline int GetValue()
{return cpri_Value_I;}

(Having nothing to do with into how many lines you write your code).
Greetings,
Nathan

##### Share on other sites
Quote:
 Original post by LonelyStarJust a notice:Maybe you are aware of this, but the two examples you posted are both NOT inlined.

... unless he left out some important context in the first case:
    class foo    {        ...        int GetValue() { return cpri_Value_I; }        ...    };

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627653
• Total Posts
2978440

• 10
• 12
• 22
• 13
• 33