# Inline Functions

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

## 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 on other sites
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;};// constructorDog::Dog( void ){	iAge = 0;	iWeight = 0;}// destructorDog::~Dog( void ){}// make the dog barkinline void Dog::Bark( void ) const{	std::cout << "Your dog says Woof!" << std::endl;}// make the dog beginline void Dog::Beg( void ) const{	std::cout << "Your dog is begging for food!" << std::endl;}// make the dog sleepinline void Dog::Sleep( void ) const{	std::cout << "Your dog is sleeping!" << std::endl;}// set the age of the doginline void Dog::SetAge( unsigned short int iVal ){	iAge = iVal;}// set the weight of the doginline void Dog::SetWeight( unsigned short int iVal ){	iWeight = iVal;}// get the dogs ageinline unsigned short int Dog::GetAge( void ) const{	return iAge;}// get the dogs weightinline unsigned short int Dog::GetWeight( void ) const{	return iWeight;}

##### Share on other sites
Quote:
 Original post by FixxerHm, 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?

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.