   How short is short?
  What is a good rule of thumb to use when determining whether or not to inline a function?  I understand that it should only be used for short and simple functions, but how long is too long to consider inlining?  For instance, is the following function too long?return pVisible ? pPict.Draw(pPosition - pHotSpot, pDrawColor) : S_OK;You have here three accesses of private data members, one call to a member function of a private data object, and two operators.  Does this push it over the line of being too complex to inline?Or how about this?return Rect((LONG)pPosition.x, (LONG)pPosition.y, (LONG)(pPosition.x + pPict.Width()), (LONG)(pPosition.y + pPict.Height()));Here you have one call to a constructor, four data casts, six calls to members of private objects, and two operators.  Is this too much for a practical inline?I''m interested to hear thoughs on the matter. 
  What I''ve heard from most other people is to not inline any   function until after 1) the program works, and 2) you''ve profiled and are sure that the function is a bottleneck.  If you know a function is a bottleneck after profiling, then I''d say to at least try an inline even on a bit larger function.  But don''t waste the compile/testing time if you don''t know it''s a critical function. ;  Don''t count the number of operations... Just use common sense: don''t inline huge functions, etc. Also, some compilers will help you with this by not inlining functions you tell them to because the inline keyword is only a suggestion to inline something. ;  Ok, look:Always, always leave function inlining disabled for debug builds. This is default in MSVC, don''t change it. Otherwise, debugging will be annoying as hell.Inline functions that would make sense to be inlined. Remember what inlining does--replaces the function call with the function. This is useful for functions which are called rarely and/or are short.The compiler reserves the right not to inline functions if cost/benefit analysis comes up short. Inlining is nota sure thing.In summary, inline functions which make sense inline. ;quote:Original post by Promit  Ok, look:Always, always leave function inlining disabled for debug builds. This is default in MSVC, don''t change it. Otherwise, debugging will be annoying as hell. Indeed, I have done so.  I just want to ensure that I am building my classes correctly.quote: This is useful for functions which are called rarely and/or are short. Really?  I thought that it would be useful for functions that are frequently called, especially for simple private data member getter functions, likeint SomeClass::GetData(){    return PrivateDataMember;}since this would remove the function overhead of a simple variable retrieval.  In a case like this, wouldn''t the inlining be more beneficial the more the getter function was called?;  oh it''s short baby ;quote:Original post by Promit  This is useful for functions which are called rarelyI believe "rarely" in this case refers to how many times in code they are actually seen, not how often they are called during execution.If, for example, you have a big long non-looping function that calls another function 80 times, then inlining would inline that function 80 times, causing huge coad-bloat.But if a function call is written only once in your entire program, but it is a part of code that executes ten thousand times a second, then making it inline won''t impact the size of your code at all, but might make it faster.So if your function is called from eight bajillion different locations in your code, it would probably be unwise to inline it, but if it is only called from a few locations, then it might be good to inline it.  The few locations from which it is called, the larger the function can be without causing major problems. ;  Check the two articles on inlining on gotw.ca. Inline and Inline Redux. Google should turn them up. ;  You know, they have drugs for that...(sorry, couldn''t resist) ;quote:You know, they have drugs for that...quote:oh it''s short babyHey, it''s not the size that counts, but how you use it. 