Thread: inline functionss

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    53

    inline functionss

    -------------------------

    I had a question regarding inline functions. When do you use then and how many of you use them a lot? It seems like it is more of a disadvantage because a functions code will be copied and if it is called a lot then then size of the executable will go up. Am I wrong?

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Huge page on it here
    Check out mainly Preludes link

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Arrow technique

    My own personal technique.. is to inline my constructors and destructors.. because odds are they will probably only be called once. { generally speaking of course; }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >because odds are they will probably only be called once.
    Once per creation of an object or temporary, yes. Also keep in mind that constructors and destructors can potentially have a lot more code than appears from the body.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    210
    Quote Originally Posted by hern
    It seems like it is more of a disadvantage because a functions code will be copied and if it is called a lot then then size of the executable will go up. Am I wrong?
    You shouldn't care too much about the size of your executable. Most of it likely comes from predefined classes (especially when using visual development tools).

    Just yesterday we (another student and I) had to optimize a given image smooth function. It was about 40 lines of code and went through the image pixel by pixel, line by line. Really clear and beautiful (as much as C can be) code.
    When we were finished with it it was ugly, about 450 lines of code, full of unrolled loops, most of it almost an exact copy&paste from a few lines above. But it was about 8 times faster than the original piece of code.

    Speed and size are in no way related in programming. At best it's an antiproportional relation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inline Definitions and Declarations?
    By legit in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2009, 01:59 PM
  2. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 03:38 PM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. Replies: 5
    Last Post: 09-17-2001, 06:18 AM