Are <number of functions> and <times function called> considered inverse proportional for inline?

I know what inline

works for tiny body functions called multiple times. If the number of calls increases, this can lead to particularly large code. But what about a large body function called just a few times?

I'm mainly interested in inline

a large body function that only gets called once, in a while loop in main()

. This function is actually the kernel, so 90% of the program and as stated is executed once per tick.
I suppose the compiler has no problem generating inline

it since I would write it myself in while

. Instead, I define it somewhere else and call it in while

.

EDIT:
I am well aware that it is inline

more suitable for the compiler than for the user, although it allows inlining unspecified functions inline

, so the user control is almost negligible. But this is fundamentally a plus in this particular case, it can serve very well.

+3


source share


4 answers


An inline function (if it is actually inline) will be exactly the same as if you just copied all the code to the places where you call this function. This way you can easily imagine how big the code will be.

Also, the operator inline

rather hints to the compiler that it would be better to embed this function in the code where it is called. But depending on the circumstances, the compiler may decide not to inline it if it thinks it would be better.



Also you can find this short faq about built-in functions

0


source


A smart idea. There are many compilers that generate timing code. They can see that your function only has one caller and insert it.



Again, since this requires generating the link-time code, the keyword inline

is not that useful anyway.

+1


source


Inline functions are simple functions that you cannot write in another file like example.cpp and include it in your main class files wherever you have class name { atributes, methods ..};

. You write "inline" before the function, and the compiler will see it as being written inside the class. This is what I know in different ways. And yes for functions that contain while, foor do as long as the loop is recomanded to write outside of the class function not in line. It's a matter of coding style.

0


source


You will probably be masking the wrong tree inline

. You need to profile your code with and without inline

to see what the effect will be. If I were a gambler, (and I am), I would argue that this will not improve performance, and it may degrade performance.

inline

tells the compiler that you want the function call to be replaced with inline at the point of the call, but the compiler can ignore your request. A few years ago it was quite common to use it inline

as a performance enhancement - sometimes it had a positive effect, sometimes it didn't. However, compilers are so good at optimizing code these days that it is foolish to outsmart the compiler in this regard. The compiler is much better than you at optimizing your code.

Also, compilers these days will very aggressively ignore your request to inline a function implementation into a site call. Most of the requests are inline

ignored. On today's hardware, this is generally a good thing considering performance. Overlay functions can actually hinder performance, as you might not realize.

inline

Not a productivity tool these days . Instead, it is something completely different. From the standard, section 7.1.2 / 4:

An inline function must be defined in every translation unit in which odr is used and must have exactly the same definition in every case (3.2). [Note: an inline function call may appear before its definition appears in the translation block. -end note] If a function definition appears in a translation block before the first declaration as inline, the program is ill-formed. If an externally linked function is declared inline in one translation unit, it must be declared inline in all translation units in which it appears; no diagnostics required. An inline function with an external link must have the same address in all translation units. A static local variable in an external inline function always refers to the same object.A string literal in the body of an external inline function is the same object in different translation units. [Note: The string Literal that appears in the default argument is not in the body of an inline function just because the expression is used in a function call from that inline function. -end note] The type defined in the body of an external inline function is the same type in every translation unit.

0


source







All Articles