DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: #define replacing functions.

  1. #16
    Join Date
    Nov 2003
    Quote Originally Posted by jonnin
    .Net help says it ignores "inline" -- if you want to override its internal decisions, you must use forceinline. No inline seems useless, as it does not inline in debug mode anyway.

    Why are loops considered bad for inline anyway? I could type a loop in that same location to do that same task. The point of inline is to avoid function call overhead when the function is invoked very often, and when the program has realtime requirements or performance requirements. If a significant amount of time is used just for the function call (time inline and function versions of the code) then it needs to be inlined (if the compiler failed to do so, you should over-rule it).
    Compilers may inline a function that contains a loop, but in many cases they won't. Most compilers use their own algorithms to predict which loops are good candidates for inlining and which ones are not. Generally speaking, a loop that has many iterations and which modifies objects, not just incrementing an int, is a poor candidate for inlining because the overhead incurred by the call is negligible compared to the time needed to execute that function. Furthermore, if the number of assmebly instructions that make up the function is too large, and that function is called very often in the program, inlining it would have an adverse effect on performance as it would bloat the executable. Nested loops are particularly bad inlile candidates.
    Remember also that if the loop body is a block, i.e., it has { and }, then inlining makes no sense because you still have a stack pushing and popping operations.
    Danny Kalev

  2. #17
    Join Date
    Apr 2006
    Zagreb, Croatia

    parameter passed in a register

    I think that compilers can only put a function's arguments in registers if the function's calling convention is fastcall. Stdcall or cdecl (c calling convention) expect parameters to be placed on the stack. Now assume that a stdcall function from your exe should be called from a plugin (dll) just as your program calls Windows API (which are all stdcall). The compiler must follow the function calling convention for this to work. But I agree with Danny that modern compilers are so good that low level programming and tweaking will gain little benefit. I've tried to speed some code by using assembly with no more then 10% increase so the best way to increase performance is by structuring your code properly.

  3. #18
    Join Date
    Nov 2003
    A typical function doesn't have any of these calling conventions, so the compiler is free to optimize the call either by inlining it altogether or by placing arguments on the stack. Also, even with respect to cdecl and stdcall, the argument ordering doesn't disable the passing of arguments on CPU registers. In fact, the this pointer is almost always passed on the register, and so is the return type of a non-void function. This is why I recommend that functions never be declared with explicit calling conventions, unless this is mandated by a certain framework. Each compiler version may use different optimization algorithms so it's best to leave this to the compiler.
    Danny Kalev

Similar Threads

  1. Need Help for a hook subclass issue in Word
    By hcadieu in forum VB Classic
    Replies: 0
    Last Post: 02-14-2006, 01:39 AM
  2. VB/C Array parameters
    By Gastao Woelfert in forum VB Classic
    Replies: 2
    Last Post: 09-01-2000, 11:36 AM
  3. VB/C Array parameters
    By Gastao Woelfert in forum VB Classic
    Replies: 0
    Last Post: 09-01-2000, 08:59 AM
  4. resize a picture or image box
    By Rally in forum VB Classic
    Replies: 2
    Last Post: 06-30-2000, 01:10 PM
  5. Adding Columns to comboboxes through API
    By Lori Taylor in forum VB Classic
    Replies: 20
    Last Post: 06-14-2000, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center