CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    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

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Why not define all functions as inline?

    Quote Originally Posted by amyahlom View Post
    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.

  3. #3
    Join Date
    Feb 2009
    Location
    USA
    Posts
    68

    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...
    Google is your friend.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Why not define all functions as inline?

    Quote Originally Posted by g.eckert View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured