Mar 5, 2010

What is Inline function in c/c++? A discussion on its Advantages,Disadvantages,Performance and Uses Guidelines.

Inline function is the optimization technique used by the compilers. One can simply prepend inline keyword to function prototype to make a function inline. Inline function instruct compiler to insert complete body of the function wherever that function got used in code.

Advantages :-
1) It does not require function calling overhead.
2) It also save overhead of variables push/pop on the stack, while function calling.
3) It also save overhead of return call from a function.
4) It increases locality of reference by utilizing instruction cache.
5) After in-lining compiler can also apply intra-procedural optimization if specified. This is the most important one, in this way compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable elimination etc..



Disadvantages :-
1) May increase function size so that it may not fit on the cache, causing lots of cahce miss.
2) After in-lining function if variables number which are going to use register increases than they may create overhead on register variable resource utilization.
3) It may cause compilation overhead as if some body changes code inside inline function than all calling location will also be compiled.
4) If used in header file, it will make your header file size large and may also make it unreadable.
5) If somebody used too many inline function resultant in a larger code size than it may cause thrashing in memory. More and more number of page fault bringing down your program performance.
6) Its not useful for embedded system where large binary size is not preferred at all due to memory size constraints.








Performance : -
Now covering the topic which most the people are interested in the "Performance".
In most of the cases Inline function boost performance if used cautiously as it saves lots of overhead as discussed in our Advantages section above but as we have also discussed  its disadvantages one need to be very cautious while using them. Today's modern compiler inline functions automatically, so no need to specify explicitly in most of the cases. Although placing inline keyword only gives compiler a hint that this function can be optimized by doing in-lining, its ultimately compiler decision to make it inline. Though there are ways to instruct compiler too, for making a function call inline like one can use __forceinline to instruct compiler to inline a function while working with microsoft visual c++. I suggest not to use this keyword until you are very sure about performance gain. Making a function inline may or may not give you performance boost, it all depends on your code flows too. Don't expect a magical performance boost by prep-ending inline keyword before a function to your code as most of the compiler nowadays does that automatically.

As we have seen inline function serves in terms of performance but one has to use it with extreme cautions.

I have prepared a few guidelines for its use.
Uses Guidelines :-
1) Always use inline function when your are sure it will give performance.
   Recently i got very good example showing immature use of inline function.
Suppose you have used inline function and for some reason compiler rejects it.
Well, when the compiler cannot inline a function, it generates a static definition of the function instead. In other words, the code for the function is generated just like the code for a static function. This means that every translation unit in which an inline function cannot be inlined will get its own copy of the function, which can increase the size of your program. Most compilers will report warnings when a function cannot be inlined. You should pay attention to these warnings to determine if some functions should not be inlined in the first place.

There is one more detail with inline functions that you should be aware of. Suppose you have chosen to use a local static variable in an inline function:

inline void foo()
{
static int index;
// ...
}

Next, suppose for some reason, the compiler cannot inline this function in several translation units. Each translation unit will then have its own static definition of foo(). But, this means that each version of foo() may also have its own copy of the static variable index! Clearly not what you want. So avoid putting static variables inside of non-member inline functions.
2) Always prefer inline function over macros.
3) Don't inline function with larger code size, one should always inline small code size function to get performance.
4) If you want to inline a function in class, then prefer to use inline keyword outside the class with the function definition.
5) In c++, by default member function declared and defined within class get linlined. So no use to specify for such cases.
6) Your function will not be inlined in case there is differences between exception handling model. Like if caller function follows c++ structure handling and your inline function follows structured exception handling.
7) For recursive function most of the compiler would not do in-lining but microsoft visual c++ compiler provides a special pragma for it i.e. pragma inline_recursion(on) and once can also control its limit with pragma  inline_depth.
8) If the function is virtual and its called virtually then it would not be inlined. So take care for such cases, same hold true for the use of function pointers.


That's it from my side, I hope you enjoyed reading the post.



169 comments:

hi
if we use macros in c code. is there any possibility of increase of page fault or overhead on register values

Please be more descriptive on it.

What does function calling overhead means?
Why avoiding it is an advantage over what inline does.

what is intraprocedural optimization? can u please explain in it depth?

This comment has been removed by the author.

According to computer experts, you are already using C++ if your computer runs on either Windows or Macintosh. This is because these operating systems were written using C++.

Interprocedural optimization (IPO) is a collection of compiler techniques used in computer programming to improve performance in programs containing many frequently used functions of small or medium length.

This is nice blog. If you want to read more on this topic, have a look here.. Inline Functions – Object Oriented Programming (OOP)

Very gud article and helps to understand easily i have also provided short info about it
meroreview forum

Great article Lot's of information to Read... Great Man Keep Posting and update to People..Thanks
SEO on page tags

It's A Great Pleasure reading your Article Bala Guntipalli Thanks for posting.

Nice article. Its really helpful to all. Thanks for sharing.
tibco Training Online

This comment has been removed by the author.
This comment has been removed by the author.

Very interesting blog Really excellent information and thank you for giving your valuable information

Workday HCM Online Training

smart outsourcing solutions is the best outsourcing training
in Dhaka, if you start outsourcing please
visit us: graphic design training
digital marketing training
Seo training in dhaka

Good Information Thanks for Sharing
Soft Online Provides best training for Oracle Fusion and EBS Courses with 100% Placements
Oracle EBS Training in Hyderabad
Oracle Fusion SCM Training
Oracle Fusion HCM Training
Oracle Fusion Financials Training
For more info Visit us: www.softonlinetraining.com

Lovely blog ..! I really enjoyed reading this article. Thank you for sharing such a wonderful post
aws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore.
Dell Boomi Training in Bangalore


Thanks for sharing such an useful and informative stuff..

iib tutorial

This comment has been removed by the author.
This comment has been removed by the author.
This comment has been removed by the author.


Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, I also want to share something sap mm module training . keep sharing.

This post is really nice and informative. The explanation given is really comprehensive and useful.

salesforce admin tutorial


Well thats a nice article.The information You providied is good . Here is i want to share about hyperion essbase training and Sap HR Training videos . Expecting more articles from you .

we are providing best salesforce CRM training and placement.

According to Business Insider, the dispute began when Oracle sued Google for the use of Java APIs that were considered illegal because Google did not pay royalties to Oracle.Google Will Use OpenJDK



I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.I want to share about Mulesoft training .

Its really informative.
Great article with excellent idea i appreciate your post thankyou so much and let keep on sharing your stuffs.
tally course in chennai

hadoop course in chennai

sap course in chennai

oracle course in chennai

angular js course in chennai

nice article thanks for sharing the great information..!

Data Science | CCNA | IOT | Ethical Hacking | Cyber Security Training in Chennai | Certification | Online Courses

data science course in chennai

ccna course in chennai

iot course in chennai

ethical hacking course in chennai

cyber security course in chennai

Thanks for sharing this with so much of detailed information, its much more to learn from your article. Keep sharing such good stuff.

Search Engine Optimization Tutorial in Hindi


Dr. Vivek Galani is a leading expert in skin and hair. At hair transplant clinic in Surat Skin Care, Cosmetic Laser, Hair Transplant & Slimming Center, Dr. Galani offers the most advanced cosmetic and dermatologic care treatments. The clinic uses advanced FUE methods to produce high-quality hair transplants.

Thank you for this important update man!
To buy a mobile is not easy when you have little money in your hand. So you can search in Quikads; a classified ads platform in Bangladesh. Where you will get so many ideas about Used phone in bd.

Repairing of Lenovo laptop are very well done by us as we have experts that are well versed with the technology used in Lenovo laptop to build them. Get in touch with us for swift & skilled help in repairing your Lenovo laptop system. Lenovo service center in Gurgaon. Call us: 7217871051
Lenovo Service Center in Gurgaon

Repairing of Lenovo laptop are very well done by us as we have experts that are well versed with the technology used in Lenovo laptop to build them. Get in touch with us for swift & skilled help in repairing your Lenovo laptop system. Lenovo service center in Delhi. Call us: 7217871051
Lenovo Service Center in Delhi

Repairing of hp laptop are very well done by us as we have experts that are well versed with the technology used in hp laptop to build them. Get in touch with us for swift & skilled help in repairing your hp laptop system. hp service center in Delhi. Call us: 7217871051
Hp Service Center in Delhi

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7217871051
Hp Service Center in Ghaziabad

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7217871051
Lenovo Service Center in Ghaziabad

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
HP Service Center in Uttam Nagar

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
Hp Service Center in Neta ji subhash Place

Email Marketing Service to engage subscribers, nurture leads, send beautiful, responsive emails and track results.

Dell Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Dell Service Center in Rajouri Garden

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service Center in Rajouri Garden

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Rajouri Garden

I just love this type of article because here i found every information that i was searching. I am taking Primavera P6 Training from ppm global services. They are really awesome at their work.

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Lenovo Service Center in Nehru-Place

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Lenovo Service Center in Pitampura

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Hp Service Center in Pitampura

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
HP Service Center in Uttam Nagar

Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Lenovo Service Center in Mangolpuri

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Hp Service in Center in Okhla

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Lenovo Service in Center in Okhla

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Lenovo Service Center in Greater Noida

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Hp Service in Center in Greater Noida



Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 7042640351.
Hp Service Center in Chattarpur



Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 7042640351.
Lenovo Service Center in Chattarpur


Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838122281.
Dell Service Center in Mumbai

The school maintains the authors' obligation to greatness in all fields, with accentuation on its maxim Higher Stronger Brighter. High ethics are an essential of a decent individual. Contact on us: 8130269997.
GD GOENKA
Top Schools in Rohini
cbse school in Rohini

Hi,
Thanks for sharing such nice informative blog and it contains so much knowledge about the topic .Please share this types of blogs on regular basis.

GD GOENKA Rohini
Best Schools in Delhi
Nursery Admissions 2021-2022
cbse school in Delhi
top 10 schools in rohini
cbse school in rohini
Top Schools in Rohini
GD GOENKA

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Hp Service Center in Mumbai

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Lenovo Service Center in Mumbai

Dell Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Dell Service Center in Mumbai

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Outdoor Advertising Companies in Delhi

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Outdoor advertising

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Hoardings in Delhi

The Company eyes the vision of getting one of the India's notable and rumored Ad Agency by satisfying our customer's requirements and giving our significant customers the best quality outcomes utilizing our ability and rich encounters of publicizing area. We have practical experience in vital and inventive Brand Promotion arrangements in OOH.
Hoardings in Delhi
Rural wall painting advertising
Digital wall painting
Transit Media Service

G.D. Goenka Public School Rohini Sector- 9 is a Co-educational Senior Secondary School, recognized and affiliated to the Central Board of Secondary Education (CBSE). It has classes from Preschool till Class 12th. The school upholds the founders' commitment to excellence in all fields, with emphasis on its motto Higher Stronger Brighter. High morals are a prerequisite of a good human being.
top 10 schools in rohini
cbse school in Delhi
Nursery Admissions 2021-2022

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Hoardings in Delhi
Digital wall painting
Auto Rickshaw advertising

Four Square Media Services is engineered in Delhi NCR. The Company eyes the vision of getting one of the India's striking and assumed Outdoor Advertising Companies in Delhi by fulfilling our client's basics and giving our colossal clients the best quality results using our ability and rich experiences of advancing. Contact on us: 9868946230.
Hoardings in Delhi
Digital wall painting
Advertising wall painting

One thing we make sure that we provide tobacco-free paan and currently we have a paan franchise in INDIA so people who want to eat paan or purchase paan just type of google paan near me and you find your nearest mast banarasi paan shops.
Karva Chauth Suhag Thali
Paan Café
Flavour Paan
Paan Franchise

Four Square Media Services is engineered in Delhi NCR. The Company eyes the vision of getting one of the India's striking and assumed Outdoor Advertising Companies in Delhi by fulfilling our client's basics and giving our colossal clients the best quality results using our ability and rich experiences of advancing. Contact on us: 9868946230.
Hoardings in Delhi
Digital wall painting
Wall painting advertising
Outdoor advertising

Mast Banarasi Paan also Provides home delivery for it all products along with the service of event management. Customers can also order delicious Paan by submitting their requests online. Mast Banarasi Paan is a natural Paan for all paan lovers because it offers the Best Goal where people belonging to all age groups can visit and eat and enjoy 120 + delicious varieties of Paan.
banarasi paan
paan near me
Flavour Paan
family paan café

Nice article bro, thanks for sharing better information. keep doing the great work bro. thanks again for this article. Fashion Bloggers In India

IGRS Telangana portal is the all type services provide in telangana state

Bs system solution in Delhi provides the best solution for laptop repair. Our experienced engineers take complete care and responsibility for your device and provide you a high-quality solution. The Lenovo Laptop Technical support is available for all range of customers. IF YOU ARE INTERESTED YOU MAY CALL -9891868324, 9643406897, and 9643409808
laptop repairing center in Delhi
best laptop service center in Delhi

Bs system solution in Delhi provides the best solution for laptop repair. Our experienced engineers take complete care and responsibility for your device and provide you a high-quality solution. The Lenovo Laptop Technical support is available for all range of customers. IF YOU ARE INTERESTED YOU MAY CALL -9891868324, 9643406897, and 9643409808
laptop service in Delhi
laptop reparing center in Mumbai

Bs system solution in Delhi provides the best solution for laptop repair. Our experienced engineers take complete care and responsibility for your device and provide you a high-quality solution. The Lenovo Laptop Technical support is available for a range of customers. IF YOU ARE INTERESTED YOU MAY CALL -9891868324, 9643406897, and 9643409808.
multi brand laptop repairing in Mumbai
Best laptop repairing center in Mumbai

https://koladblog.com.ng/2021/10/08/top-6-really-free-vpn-for-android/

One of the best articles is this. I am looking for this article for a long time. At last, I found this on your website. Many many thanks for sharing your content.
Bangla Calendar 2022
Cool and beautiful stylish name

https://applelaptopservice.center/dell-service-center-mumbai/

Thank YOu
https://applelaptopservice.center/dell-service-center-mumbai/

i like your post and all your headings are good....hindi skill

Thank You! For sharing such a great article, It’s been a amazing article. India No.1 Media

I learned a lot from this information. Thanks you. I want to share about best micronutrients for plants

Hey, I like this and its helpful for me and i appreciate your work & Hope to see more post In future Buy Instagram Followers In India

I really enjoyed your blog Thanks for sharing such an informative post.

Step-by-Step Hacking Tutorials about WiFi hacking,
Kali Linux, Metasploit, exploits, ethical hacking, information security, malware analysis and scanning
hacking

Are you looking for a way to watch the latest Pathan movie in high-quality and for free? Look no further! Here we provide you with the best options to Pathan Full Movie Download 4K, HD, 1080p 480p, 720p in Hindi quality for free in Hindi. We have compiled a list of reliable sources that offer the highest quality streaming and downloading services. So get ready to dive into the world of Pathan with this ultimate guide on how to download it for free !

"Very Informative Blog" If you want to know further informations Find out more

Amazing Write - up, this blog clearly explains on its contents and provides adequate information.
Find Here

Amazing write up , For more information's Click Here

Much needed information, If you are interested in knowing more details Check Here

Great content. Thank you for sharing such a nice and interesting blog with us.
New updates
Information

Amazing write up, For informations Follow here

Very Informative Blog. If you want to know further information check out here

Well researched and well written .
For more such info:
click here

Thanks in favor of sharing such a nice thought, post is pleclick hereasant, thats why I have read it completely. For more

Thanks in favor of sharing such a nice thought, post is pleasant, thats why I have read it completely. For more click here

AVEVA System Platform supplier & solutions provider of AVEVA System Platform, quick technical support in India & globally.

Thanks a lot for your interesting article. I have been searching for such message for a very long time. Not all your content is completely clear to me, even though it is definitely interesting and worth reading. Goviralhost Review

Great learning experience. For more such content visit our website https://www.cloudthat.com/training/

I really liked your point about, I've been struggling with this myself, so I'll definitely be trying out your tips."
bus rental Dubai

Maharaja Online is a premier online betting platform in India, offering a thrilling and secure betting experience.
Visit- Casino in Bangalore India

Very Nice Post.....Thanks for Sharing This Useful Information.....
When it comes to fixing your Dell laptop, trust BSS Laptop Repair Center in Sion as your go-to destination. Our expert technicians specialize in providing top-notch Dell Laptop Repair Service in Sion tailored specifically for Dell laptops. Whether you are facing hardware issues or software malfunctions, we are equipped to handle any problem efficiently. With our dedication to customer satisfaction and years of experience, BSS Laptop Repair Center is the ultimate choice for all your Dell laptop repair needs in Sion. Visit our center today and experience reliable service you can count on.


Dell Laptop Repair Service in Sion
Dell Laptop Repair Service in Nariman Point
Dell Laptop Repair Service in Malad
Dell Laptop Repair Service in Borivali
Dell Laptop Repair Service in Jogeshwari
Dell Laptop Repair Service in Dadar
Dell Laptop Repair Service in Kandivali
Dell Laptop Repair Service in Bandra

Post a Comment