Is it possible that code of method from a referenced dll gets inlined in my own code?

233 views Asked by At

A while ago I've read something about 'inlining'. The .Net compiler will inject code (inline) from small methods to make execution quicker.

Is it possible that code of method from a referenced dll gets inlined in my own code?

4

There are 4 answers

2
Lasse V. Karlsen On BEST ANSWER

Yes, that is possible, at JITting time.

Not at compile time.

Which means that your assembly will only contain the code you wrote it with, but when it is JITted into native machine code at runtime, the JIT compiler might inline small methods from other assemblies into your own code.

2
Jonathan Allen On

Yes. If you don't pre-compile the assembly using ngen.exe then the JIT compiler can inline across assemblies automatically.

2
AbiusX On

To be precise, No.

But if the Lib of the DLL is available (DLL stands for Dynamically Linked Library, something we can not link statically) it might happen.

Auto inlining as an step of optimization, is only performed on small functions or functions used very rarely, But always on libs.

To conclude, A static link library (*.lib in Windows or .a in Unix) could be copied into your program but a dynamic link library (.dll in Windows or *.so in UNIX) couldn't.

In case of .NET or similar frameworks, the story is a little different.

2
fixagon On

its generally very possible. but you cant decide yourself, its the compiler which decides:

check that: http://www.ademiller.com/blogs/tech/2008/08/c-inline-methods-and-optimization/