Function call: how does it cost?

This is a discussion on Function call: how does it cost? within the C Programming forums, part of the General Programming Boards category; Hi guys, I have a bigger function that calls, in mean 1000-2000 times, a smaller function. I "discover" that calling ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    50

    Function call: how does it cost?

    Hi guys,
    I have a bigger function that calls, in mean 1000-2000 times, a smaller function. I "discover" that calling the smaller function make the code very slow. Is there any hint to fix it? I read about inline functions, but they did not help me...
    Thank you!
    ai confini della conoscenza

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,893
    Declaring the function inline is your best bet, unless you want to turn the smaller function into a macro. Besides declaring the function as inline, the definition of the function should also be available to the caller, i.e., you may need to place it in the header, contrary to normal separation of forward declarations of functions in header files and their definitions in source files.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    50
    awesome! Now the code takes half of the time. I did not put the inline function in the header, but after your advise I did it and it works! Thank you!
    ai confini della conoscenza

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Loading files with a function call
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 04-10-2007, 07:19 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21