Skip to main content

Inline Functions and their Uses

It’s a good practice to divide the program into several functions such that parts of the program don’t get repeated a lot and to make the code easily understandable.

We all know that calling and returning from a function generates some overhead. The overhead is sometimes to such an extent that it makes significant effect on the overall speed of certain complex and function-oriented programs. In most cases, we have only a few functions that have extensive use and make significant impact on the performance of the whole program.

Not using functions is not an option, using function-like macros is an option, but there is a better solution, to use Inline Functions.

Yes, like it sounds, inline functions are expanded at the place of calling rather than being “really called” thus reducing the overhead. It means wherever we call an inline function, compiler will expand the code there and no actual calling will be done.

Member functions of classes are generally made inline as in many cases these functions are short but any other function can be inline too. Functions are made inline by preceding its definition with the keyword “inline” as shown in the example below:

// precede the definition
// of function with "inline"
// it's optional to do so for
// the prototype
inline ret-type func-name(arg-list...)
{
...
...
...
}


Member functions (class) can be made inline as below:

class myclass
{
private:
...
...

public:
ret-type func-name(arg-list...);
...
...
};

inline ret-type myclass::func-name(arg-list...)
{
...
...
}


Or simply as

class myclass
{
private:
...
...

public:
inline ret-type myclass::func-name(arg-list...)
{
...
...
}
...
...
};


Short member functions are usually made inline as above.

Please mote one thing though, inline is a request to the compiler and not a command which means it depends on the compiler and the conditions whether a particular function will be really made “inline” or not.

As inlining increases duplication of parts of code, performance will be gained at the expense of program size, which is pretty obvious. As I’ve said not all functions make major impact on the overall performance of the program. So we should carefully select which functions to inline and which not to, because if we inline many functions we can’t be sure of whether it’d do any better to the performance, but it’s for sure that program size will increase unnecessarily.

Comments

Popular posts from this blog

Death of a Star! in Bollywood

When I was flipping through my Diary 2002 the other day, my jottings about Monal’s tragic end beckoned me and brought to my mind a host of awesome nostalgic thoughts. I had a feeling of déjà vu as the dead artist again touched a chord in my heart. How would emotionally deplete artists behave when driven to wall? [Read on…] Monal, a starlet from Bollywood, hung herself to death on the Tamil New Year’s Day. A strange quirk of fate played havoc with her life, putting off her promising career of becoming an icon in the Kollywood. TV visuals showed her sleeping eternally on a bier; she was a feast to flies that were swarming her lissome body … a body that set fire to the hearts of thousands of her fans. Monal’s premature death moved me to a great extent not because she was one of the upcoming actors of the Kollywood and a diva for whom the tinsel world plumped rather madly, but because it set me thinking as to what led the young actor to kill herself savagely in the middle of her ...

Ssc combined graduate level exam syllabus and exam detail

q Tier-I of the Examination: General Intelligence & Reasoning : It would include questions of both verbal and non-verbal type. This component may include questions on analogies, similarities and differences, space visualization, spatial orientation, problem solving, analysis, judgment, decision making, visual memory, discrimination, observation, relationship concepts, arithmetical reasoning and figural classification, arithmetic number series, non-verbal series, coding and decoding, statement conclusion, syllogistic reasoning etc. The topics are, Semantic Analogy, Symbolic/Number Analogy, Figural Analogy, Semantic Classification, Symbolic/Number Classification, Figural Classification, Semantic Series, Number Series, Figural Series, Problem Solving, Word Building, Coding & de-coding, Numerical Operations, symbolic Operations, Trends, Space Orientation, Space Visualization, Venn Diagrams, Drawing inferences, Punched hole/pattern –folding & unfolding, Figural Pattern – folding...

27 Simple mehndi designs for hands for Karwa Chauth

The most  simple mehndi designs for hands  for Karwa Chauth 2014 Karwa Chauth  is around the corner and I am so excited about getting mehndi done! This time I plan to go with a simple yet quirky design. Don’t want my hands full, however it needs to be a style statement for this year’s most awaited festival for us ladies! There are some basic categories of mehndi designs, such as Gujrati, Rajasthani, Marwari,  Arabic  and African  patterns to choose from. They have certain prominent motifs or symbols that distinguishes one from the other. I just can’t seem to stop experimenting with these styles. From  circles to squares , peacocks and paisleys , checks and dots and what not. But my all-time favorite is a simple, curling vine, of course finger tips covered with thick coating of aromatic mehndi (which is so traditional). Quirky patterns include  traditional  as well as non-traditional patterns tweaked to one’s own liking. This includ...