By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

inline

100+
P: 553
Whats the benefit of using inline. This is the text from microsoft website on inline.

"The inline and __inline specifiers instruct the compiler to insert a copy of the function body into each place the function is called. "

and i understand this.. but hard to understand the benefit of doing this.

the called code will be copied at the calling point.. this is extra work to do for compiler,, and not very inefficient, is it?
Aug 5 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
When you call a function, memory must be allocated for the function arguments and the local variables. This is called a stack frame and the address of the memory is managed by a data structure called a stack. This is a last-in-first-out linked list.

All of this takes time.

Inline avoids this overhead at the expense of program memory footprint. The body of the function is copied every time it is called. You run faster but wih a larger program.

Many optimizers when encountering functions of one or two lines of code will make them inline whether you said to or not.
Aug 5 '07 #2

Expert 10K+
P: 11,448
When you call a function, memory must be allocated for the function arguments and the local variables. This is called a stack frame and the address of the memory is managed by a data structure called a stack. This is a last-in-first-out linked list.

All of this takes time.

Inline avoids this overhead at the expense of program memory footprint. The body of the function is copied every time it is called. You run faster but wih a larger program.

Many optimizers when encountering functions of one or two lines of code will make them inline whether you said to or not.
The GNU compiler suite can do it 'halfway' too: for any function with no local
variables, no stack frame is set up on entry of the function and no stack frame
needs to be restored on exiting the function. It's a great micro optimization but
the debugger doesn't like it ;-)

kind regards,

Jos
Aug 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.