• Advertisement
Sign in to follow this  

Inline Functions

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

When is it better to use inline functions? I am assuming for games, inline functions should be used as much as possible so that the game runs faster, and the exe doesnt have to jump from section to section as much.

Share this post


Link to post
Share on other sites
Advertisement
Hm, so functions that take up only a few lines would be better as inline, but larger ones could be better as just a plain function?

Blah, it seems to be it doesnt matter that much anyway, since computers now a days are so fast.

Little functions like these would be good as inline I am guessing


class Dog
{
public:
Dog( void );
~Dog( void );

void Bark( void ) const;
void Sleep( void ) const;
void Beg( void ) const;

void SetAge( unsigned short int iVal );
void SetWeight( unsigned short int iVal );

unsigned short int GetAge( void ) const;
unsigned short int GetWeight( void ) const;

private:
unsigned short int iAge;
unsigned short int iWeight;
};

// constructor
Dog::Dog( void )
{
iAge = 0;
iWeight = 0;
}

// destructor
Dog::~Dog( void )
{

}

// make the dog bark
inline void Dog::Bark( void ) const
{
std::cout << "Your dog says Woof!" << std::endl;
}

// make the dog beg
inline void Dog::Beg( void ) const
{
std::cout << "Your dog is begging for food!" << std::endl;
}

// make the dog sleep
inline void Dog::Sleep( void ) const
{
std::cout << "Your dog is sleeping!" << std::endl;
}

// set the age of the dog
inline void Dog::SetAge( unsigned short int iVal )
{
iAge = iVal;
}

// set the weight of the dog
inline void Dog::SetWeight( unsigned short int iVal )
{
iWeight = iVal;
}

// get the dogs age
inline unsigned short int Dog::GetAge( void ) const
{
return iAge;
}

// get the dogs weight
inline unsigned short int Dog::GetWeight( void ) const
{
return iWeight;
}


Share this post


Link to post
Share on other sites
Quote:
Original post by Fixxer
Hm, so functions that take up only a few lines would be better as inline, but larger ones could be better as just a plain function?

You haven't read the link, have you:
Quote:
There are no simple answers: You have to play with it to see what is best. Do not settle for simplistic answers like, "Never use inline functions" or "Always use inline functions" or "Use inline functions if and only if the function is less than N lines of code." These one-size-fits-all rules may be easy to write down, but they will produce sub-optimal results.


Quote:
Blah, it seems to be it doesnt matter that much anyway, since computers now a days are so fast.

Right you are. Make working, algorithmically optimized code first. Micro-optimize later.

Share this post


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

  • Advertisement