Windows GDI and Speed question - inline; lazarus / 39-Graphics ---------------------------------------------------------------------- PeterX · 2016-10-10 10:19 Hi all, - Windows GDI - I'm currently working on some old foreign (Delphi) sources, under Lazarus. There I found several code blocks that are redundant (fully the same code), calling several - FillRect() - MoveTo() - LineTo() - DrawText() etc. ... I could put them into some plain pascal subfunctions (to reduce redundancy). => So with using inline; the FPC compiler should put the code inplace (I think ..?) Does it eat up relevant system CPU time  if I do NOT use inline; with such subfunctions ? ---------------------------------------------------------------------- marcov · 2016-10-10 10:32 Rule of thumb is that Inline is only increases speed when the routines to be inlined are relative short, and simple. It can work speed decreasing if too long procedures are inlined, specially in a otherwise relatively short loop. And all these effects won't really be noticable unless you really get into hundreds of thousands or million times per second magnitudes. (like operating on every pixel in image analysis) In case of doubt: don't inline or benchmark, and in time you'll get a feel for it. ---------------------------------------------------------------------- PeterX · 2016-10-10 11:59 Quote from: marcov on October 10, 2016, 12:32:59 pmRule of thumb is that Inline is only increases speed when the routines to be inlined are relative short, and simple. Okay, these Windows API functions are definetly not short or simple. I'll try. If painting doesn't make any difference, .. I will avoid inline; Thanks for Your hints ! ---------------------------------------------------------------------- Bart · 2016-10-10 12:06 AFAIK inline is a request to the compiler to inline the code, but that request may not always be honoured. Bart ---------------------------------------------------------------------- marcov · 2016-10-10 12:51 Quote from: Bart on October 10, 2016, 02:06:35 pmAFAIK inline is a request to the compiler to inline the code, but that request may not always be honoured. True, but that is afaik mainly across unit divisions. Delphi even has hints for this. ---------------------------------------------------------------------- circular · 2016-10-10 13:18 As marcov says, inline functions need to be small. Basically, not doing "inline" requires to: - push some registers on the stack - copy the values of parameters This is not significant compared to drawing shapes. In fact calling functions can be very fast so that the use "inline" is rare unless you're doing low level programming. ---------------------------------------------------------------------- PeterX · 2016-10-10 14:49 Quote from: circular on October 10, 2016, 03:18:15 pmIn fact calling functions can be very fast so that the use "inline" is rare unless you're doing low level programming. Until now I only used inline; for small ASM functions. Using functions for these GDI subjobs will make my code smaller and easier to maintain. ---------------------------------------------------------------------- circular · 2016-10-10 16:06 Yes, you can definitely afford putting those into functions. ---------------------------------------------------------------------- marcov · 2016-10-10 16:07 and assembler is currently never inlined anyway ---------------------------------------------------------------------- PeterX · 2016-10-10 19:21 Quote from: marcov on October 10, 2016, 06:07:11 pmand assembler is currently never inlined anyway Oh ? Something like that can't be "inlined" ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function AsmFn( A, X: Extended):Extended; {$ifdef FPC}assembler;{$endif}{$ifdef FPC} {$ASMMODE intel} {$endif}asm        // do some intel style ASM operations ..end; (  I just saw, indeed I never tried on my asm functions ..    ) But I did it on this one, for example  ( to appease the angry "Hints"-Ghost in Laz .. ) : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function PtrToInt( p:pointer):integer; {$IFDEF FPC}inline;{$ENDIF}begin  Result:= {%H-}PtrInt( p);end;