inline function

imrankhan2085 3,681 views 13 slides Dec 26, 2016
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

inline function definition uses advantages and disadvantages


Slide Content

PRESENTATION TOPIC INSLINE FUNCTION REPRRESENTATOR : IMRAN KHAN FAHAD NUOMAN

Contents : INLINE FUNCTION Syntax Example USES ADVANTAGES DISADVANTAGES

What is inline function ? INLINE FUNCTION : . If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time

Syntax of inline function Inline return _type fun_name (arguments)

#include< iostream > using namespace std ; inline int max( int x, int y) { return (x>y) ? x : y; } int main() { int a,b ; cout <<"enter value for a"<< endl ; cin >>a; cout <<"enter value for b"<< endl ; cin >>b; cout <<"greater value is"<<max( a,b ); return 0; }

Working procedure of inline functions

Uses Of INLINE FUNCTION : To reduce and save the memory space . The inline function is just a code replacement instead of the function call . inline is a hint or request to compiler and its used to avoid function call overheads.

Advantages:- It speeds up your program by avoiding function calling overhead. It save overhead of variables push/pop on the stack, when function calling happens. It save overhead of return call from a function. It increases locality of reference by utilizing instruction cache .

By marking it as inline, you can put a function definition in a header file (i.e. it can be included in multiple compilation unit, without the linker complaining)

Disadvantages:- It increases the executable size due to code expansion.  C ++ inlining is resolved at compile time. Which means if you change the code of the inlined function, you would need to recompile all the code using it to make sure it will be updated. When used in a header, it makes your header file larger with information which users don’t care. As mentioned above it increases the executable size, which may cause thrashing in memory. More number of page fault bringing down your program performance.

As mentioned above it increases the executable size, which may cause thrashing in memory. More number of page fault bringing down your program performance.