tags:

views:

72

answers:

3

Say you override operator* for point3 and float and then for float and point3 you used the operator like this:

point3 * float

Can you know if the operator method is going to end up inlined?

+2  A: 

As far as I know there is no way to know for certain as the JIT is responsible for inlining.

Andrew Hare
+5  A: 

No, you can't tell for sure. In particular, because it's done at JIT time, it will depend on the version of the CLR - and I believe that the 64 bit CLR inlines differently to the 32 bit one as well. It will also depend on whether optimisations are enabled (e.g. whether you're debugging etc).

You can prevent inlining with MethodImplAttribute, but that doesn't help much...

Jon Skeet
Thanks Jon. Out of curiosity, do you know why would one wanna prevent it?
Joan Venge
In my experience, to benchmark how much difference it makes :) I guess there could be places where you want to make sure you get a valid stack trace, but they're going to be few and far between.
Jon Skeet
Thanks Jon. I got it now.
Joan Venge
+2  A: 

There is no way to know if a particular method will be inlined or not. C# itself won't ever inline a method call. Only the JITer will do this. While there are certain operations that are likely to be inlined, the JITer makes no guarantees.

JaredPar