Download

Can someone explain FORCEINLINE to someone who knows virtually nothing about C++?

I looked at it on the wiki but I still really don’t understand.

Thanks!

I dont know exactly what force inline does… but inline IIRC works as follow:

Instead of make a normal call at processsor level, it uses the code of the function to generate it inline where you called the function, so, inlined functions are “faster” to call… ie it is more like you have pasted the code inside your code, instead of call it.

You do inline code in header files (I think you cant use a inline function if you dont have actually the source of the function), so each time you compile/link, even if you dont have the cpp (ie you only have alib) you still have the code because you have the header files.

Or in other words if that doesnt make sense, think of inline functions as copy and paste, instead of call (push arguments, save return address and jump to target function instructions on assembler).

http://www.cprogramming.com/tutorial/lesson13.html

Why unreal need INLINEFUNCTION (most probably a macro?), we will need to pick on the definition to see what extra things they add, maybe something for blueprints recognize this functions or something like htat.

In C++ the inline keyword is used to say you’d like the compiler to, instead of calling to this function where it appears, put the instructions directly in the binary, as though you’d written the contents of your function each place it gets called.

Calling a function has some overhead to it, so the idea is that it gets rid of this overhead by instead having the machine code do the work where it would have called the function. The tradeoff is that instead of having your instructions stored once in memory, they’re stored everywhere a call to it appears.

The inline keyword is just a suggestion though; the compiler can choose to ignore it (or to inline functions which you didn’t add the keyword to).

So, while I’ve not looked into FORCEINLINE (i.e. I could be totally, shamefully, mock-me-until-I-die wrong), my guess would be that it makes sure the compiler doesn’t just take it as a hint, but that it’s actually inlined regardless of how the compiler feels about it.

Cheers,

Alan.

Great thanks for the replies!