|
-
October 16th, 2009, 07:14 AM
#1
Why not define all functions as inline?
This will save the time of passing arguments and return value (stack)
It is true that the code will have bigger size, but why care?
Why prefer inlining short function instead of long ones?
Thanks,
Ron
-
October 16th, 2009, 07:34 AM
#2
Re: Why not define all functions as inline?
 Originally Posted by amyahlom
This will save the time of passing arguments and return value (stack)
It is true that the code will have bigger size, but why care?
Why prefer inlining short function instead of long ones?
Thanks,
Ron
Really?
You had to ask in a forum?
I'm sure there are like 1000 articles explaining this.
The reason you want to keep your program small is not because of hard drive space. A big program will run slower than a smaller one, even with less jumps. A processor doesn't have much more than a few megs to store your program. If your executable is bigger than that, you will lose tons of time moving it from cache to ram.
Besides, function calls are not very expensive if you don't pass arguments by value.
Not to mention that a program where everything is inline will take years to compile, and you will create tons of dependencies.
There are tons of reason, too many to explain here. I highly recommend you try to find a good article about it. There too much to explain in a single post.
-
October 16th, 2009, 01:00 PM
#3
Re: Why not define all functions as inline?
dont inline functions just get thrown into the code everyplace they are used? That would be like typing the same piece of code 15 times in your program...
-
October 16th, 2009, 03:08 PM
#4
Re: Why not define all functions as inline?
 Originally Posted by g.eckert
dont inline functions just get thrown into the code everyplace they are used? That would be like typing the same piece of code 15 times in your program...
Not necessarily. The "inline" keyword, and putting your code in your class definition is just a suggestion to the compiler to inline the code. If there is something "funny", or the compiler is having a rough day, it may not inline any of your code.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|