Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does this attribute do: MethodImplOptions.NoInlining (or: what is 'inlining' a method) [duplicate]

Tags:

c#

Possible Duplicate:
Inline functions in C#?
What is method inlining?

i've been debugging code, and a 'possible' source of the issue is in a function which is marked with this code:

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] protected virtual void PropertyHasChanged() 

Reading MSDN says this: Specifies that the method cannot be inlined.

But what is 'inlining' a method?

EDIT:

To clarify: the PropertyHasChanged() method is called in the SET method of every property and updates (adds 1 to it) an internal object counter. When that counter > 0, the object is marked as 'dirty' and will be saved to the database when Save is called. When the counter = 0, the object will not be saved to the database. Now i've got the idea that this code sometimes is not executed (the counter is not increased) so the object won't be saved to the database,

like image 308
Michel Avatar asked Mar 07 '12 11:03

Michel


1 Answers

Inlining a method/property means that the compiler takes it and replaces the calls to it with its contents (making sure correct variables etc). This is not something that is C# specific.

This is done for performance normally.

For example, with this method and call:

private long Add(int x, int y) {    return x + y; }  var z = Add(x, y); 

The compiler may inline it as (eliminating the method in the process):

var z = x + y; 

The Wikipeida article Inline expansion starts with:

In computing, inline expansion, or inlining, is a manual or compiler optimization that replaces a function call site with the body of the callee. This optimization may improve time and space usage at runtime, at the possible cost of increasing the final size of the program (i.e. the binary file size).

like image 174
Oded Avatar answered Sep 28 '22 06:09

Oded