473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to avoid inlining?

I have some code which looks like that:

[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get { return this["RectCornerMode"].GetValue<CornerStyle>(); }
set { this["RectCornerMode"].SetValue<CornerStyle>(value); }
}
in this[string] I get the attribute decorating the calling method, and used
it to compute a default value.
now it seems that sometimes (when build in release mode) the property is by
passed and the calling method call this[string] and GetValue directly, thus
ignoring the decorating attribute....

is there a way to avoid this inlining?
any suggestion?

Apr 27 '07 #1
15 3014
found it: MethodImplAttribute.
Anyway I thought of a better solution...

--
Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com
"Lloyd Dupont" <net.galador@ldwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
>I have some code which looks like that:

[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get { return this["RectCornerMode"].GetValue<CornerStyle>(); }
set { this["RectCornerMode"].SetValue<CornerStyle>(value); }
}
in this[string] I get the attribute decorating the calling method, and
used it to compute a default value.
now it seems that sometimes (when build in release mode) the property is
by passed and the calling method call this[string] and GetValue directly,
thus ignoring the decorating attribute....

is there a way to avoid this inlining?
any suggestion?
Apr 27 '07 #2
Make it virtual. JIT can't inline virtual calls (not quite sure if this is
"better solution" for you)

"Lloyd Dupont" <net.galador@ldwrote in message
news:%2*****************@TK2MSFTNGP03.phx.gbl...
found it: MethodImplAttribute.
Anyway I thought of a better solution...

--
Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com
"Lloyd Dupont" <net.galador@ldwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
>>I have some code which looks like that:

[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get { return this["RectCornerMode"].GetValue<CornerStyle>(); }
set { this["RectCornerMode"].SetValue<CornerStyle>(value); }
}
in this[string] I get the attribute decorating the calling method, and
used it to compute a default value.
now it seems that sometimes (when build in release mode) the property is
by passed and the calling method call this[string] and GetValue directly,
thus ignoring the decorating attribute....

is there a way to avoid this inlining?
any suggestion?

Apr 27 '07 #3
>Make it virtual. JIT can't inline virtual calls (not quite sure if this is
"better solution" for you)
Sounds like a horrible solution to me. Making a member virtual just to
achieve this side effect just seems wrong. You should only make a
member virtual when it makes sense to do so and you're prepared to
handle the fact that your code may be overridden and perhaps never
run.

Plus your code would break if a future version of the CLR (or some
other runtime implementation) actually supported inlining virtual
methods.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 27 '07 #4
Mattias,
That's exactly what I meant by stating "not quite sure if this is "better
solution" for you". It's in fact a very bad "solution". Posted just to
present another alternative to using the MethodImpl attribute which is the
best solution to avoid inlining.

"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:un**************@TK2MSFTNGP06.phx.gbl...
>
>>Make it virtual. JIT can't inline virtual calls (not quite sure if this is
"better solution" for you)

Sounds like a horrible solution to me. Making a member virtual just to
achieve this side effect just seems wrong. You should only make a
member virtual when it makes sense to do so and you're prepared to
handle the fact that your code may be overridden and perhaps never
run.

Plus your code would break if a future version of the CLR (or some
other runtime implementation) actually supported inlining virtual
methods.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Apr 27 '07 #5
KKS
Your class could inherit from MarshalByRefObject. This would also achive non
inlining and is the purpose of the class altogether.

Regards
Kjetil Kristoffer Solberg
"Lloyd Dupont" <net.galador@ldwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
>I have some code which looks like that:

[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get { return this["RectCornerMode"].GetValue<CornerStyle>(); }
set { this["RectCornerMode"].SetValue<CornerStyle>(value); }
}
in this[string] I get the attribute decorating the calling method, and
used it to compute a default value.
now it seems that sometimes (when build in release mode) the property is
by passed and the calling method call this[string] and GetValue directly,
thus ignoring the decorating attribute....

is there a way to avoid this inlining?
any suggestion?

May 4 '07 #6
On May 4, 8:52 am, "KKS" <kks at synergi dot comwrote:
Your class could inherit from MarshalByRefObject. This would also achive non
inlining and is the purpose of the class altogether.
No, that's not the purpose of that class at all. The purpose of that
class is to create a COM server object, which is anchored to the
machine on which its running (that is, using the object from other
computers will perform RPC calls to the server).

Actually I'm not sure that inheriting that class will prevent inlining
at all. The only good solution is the attribute mentioned above.

May 4 '07 #7
Andy <an***@med-associates.comwrote:
On May 4, 8:52 am, "KKS" <kks at synergi dot comwrote:
Your class could inherit from MarshalByRefObject. This would also achive non
inlining and is the purpose of the class altogether.

No, that's not the purpose of that class at all. The purpose of that
class is to create a COM server object, which is anchored to the
machine on which its running (that is, using the object from other
computers will perform RPC calls to the server).
I think that definition is too narrow as well. COM doesn't need to be
involved anywhere. It just means (IMO) that when an instance needs to
be marshalled across an AppDomain boundary - for whatever reason - the
reference will be used, rather than creating a value copy of the
object.
Actually I'm not sure that inheriting that class will prevent inlining
at all.
I believe that it currently prevents inlining, but I haven't seen
anything to actually specify that, or say that it will always be the
case.
The only good solution is the attribute mentioned above.
Agreed.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 4 '07 #8
On May 4, 10:01 am, Jon Skeet [C# MVP] <s...@pobox.comwrote:
I think that definition is too narrow as well. COM doesn't need to be
involved anywhere. It just means (IMO) that when an instance needs to
be marshalled across an AppDomain boundary - for whatever reason - the
reference will be used, rather than creating a value copy of the
object.
Yes, you are right.
I believe that it currently prevents inlining, but I haven't seen
anything to actually specify that, or say that it will always be the
case.
Inlining is a compiler trick, isn't it? I didn't see anything on the
MBR class that would affect inlining, unless I'm missing it somewhere..

May 4 '07 #9
Andy <an***@med-associates.comwrote:

<snip>
I believe that it currently prevents inlining, but I haven't seen
anything to actually specify that, or say that it will always be the
case.

Inlining is a compiler trick, isn't it? I didn't see anything on the
MBR class that would affect inlining, unless I'm missing it somewhere..
It's done by the JIT, not by the C# -IL compiler. I don't know the
details about why inlining doesn't take place, but I'm sure I've seen
it in the past in other questions.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 4 '07 #10
You are mistaken.

The MarshalByRefObject has a bad name. It's primary purpose is to supress
inlining by the JIT compiler so that the transparent proxy can do it's job.
The JIT compiler checks to see if a class inherits from MarshalByRef object
and don't inline if it does.
Regards
Kjetil Kristoffer Solberg
"Andy" <an***@med-associates.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On May 4, 8:52 am, "KKS" <kks at synergi dot comwrote:
>Your class could inherit from MarshalByRefObject. This would also achive
non
inlining and is the purpose of the class altogether.

No, that's not the purpose of that class at all. The purpose of that
class is to create a COM server object, which is anchored to the
machine on which its running (that is, using the object from other
computers will perform RPC calls to the server).

Actually I'm not sure that inheriting that class will prevent inlining
at all. The only good solution is the attribute mentioned above.
May 7 '07 #11
On Mon, 07 May 2007 08:47:02 -0700, Kjetil
<"kjetil[ANTI-SPAM]"@kjetil.infowrote:
You are mistaken.

The MarshalByRefObject has a bad name. It's primary purpose is to
supress inlining by the JIT compiler so that the transparent proxy can
do it's job.
From the MSDN documentation for MarshalByRefObject:

Enables access to objects across application domain
boundaries in applications that support remoting.

There's nothing in there about inlining at all. In fact, on that page
(http://msdn2.microsoft.com/en-us/lib...refobject.aspx)
there is no reference to inlining at all.

You'd think that if the "primary purpose is to suppress inlining by the
JIT compiler", some mention of inlining would show up *somewhere* in the
documentation.

I don't find the claim that MarshalByRefObject has as its primary purpose
suppression of inlining is in any way credible.
The JIT compiler checks to see if a class inherits from MarshalByRef
object and don't inline if it does.
It may well be that the compiler special-cases the class inheritance and
that inlining doesn't happen for particular classes, like
MarshalByRefObject. But that doesn't mean that's the purpose of
inheriting from MarshalByRefObject.

Pete
May 7 '07 #12
You need to look at the broader picture. Where does MarshalByRefObject get
used? In scenarios like cross appdomain/process/machine method calls, you
need a mechanism for transforming your stack based method call into some
transportable format, transport the call, then transforming it back into
stack based method calls in or on the target appdomain/process/machine, and
the same back again. This is where the transparent proxy, real proxy and
MarshalByRefObject objects come into the picture. In order for the
transparent proxy to intercept all calls there needs to made sure that no
inlining takes place. How could the transparent proxy transform a method
call and send it to the real proxy if the JIT compiler inlined the method?
It is here that MarshalByRefObject comes to the rescue. To ensure that all
method calls are intercepted by the transparent proxy you inherit from
MarshalByRefObject. Hope this makes things clearer.
Regards
Kjetil Kristoffer Solberg

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 07 May 2007 08:47:02 -0700, Kjetil
<"kjetil[ANTI-SPAM]"@kjetil.infowrote:
>You are mistaken.

The MarshalByRefObject has a bad name. It's primary purpose is to
supress inlining by the JIT compiler so that the transparent proxy can
do it's job.

From the MSDN documentation for MarshalByRefObject:

Enables access to objects across application domain
boundaries in applications that support remoting.

There's nothing in there about inlining at all. In fact, on that page
(http://msdn2.microsoft.com/en-us/lib...refobject.aspx)
there is no reference to inlining at all.

You'd think that if the "primary purpose is to suppress inlining by the
JIT compiler", some mention of inlining would show up *somewhere* in the
documentation.

I don't find the claim that MarshalByRefObject has as its primary purpose
suppression of inlining is in any way credible.
>The JIT compiler checks to see if a class inherits from MarshalByRef
object and don't inline if it does.

It may well be that the compiler special-cases the class inheritance and
that inlining doesn't happen for particular classes, like
MarshalByRefObject. But that doesn't mean that's the purpose of
inheriting from MarshalByRefObject.

Pete
May 7 '07 #13
On Mon, 07 May 2007 11:50:30 -0700, Kjetil
<"kjetil[ANTI-SPAM]"@kjetil.infowrote:
You need to look at the broader picture.
You need to read the documentation.

A class derived from MarshalByRefObject inherits a LOT more than just
suppression of inlining, and it's farcical to suggest that the primary
purpose of deriving from that class is to suppress inlining, or even that
deriving from that class is an appropriate way to suppress inlining in the
general case, especially when there's a perfectly good attribute that can
be applied to the function where inlining needs to be suppressed.

Pete
May 7 '07 #14
Kjetil <kjetil[ANTI-SPAM]@kjetil.infowrote:
You need to look at the broader picture. Where does MarshalByRefObject get
used? In scenarios like cross appdomain/process/machine method calls, you
need a mechanism for transforming your stack based method call into some
transportable format, transport the call, then transforming it back into
stack based method calls in or on the target appdomain/process/machine, and
the same back again. This is where the transparent proxy, real proxy and
MarshalByRefObject objects come into the picture. In order for the
transparent proxy to intercept all calls there needs to made sure that no
inlining takes place. How could the transparent proxy transform a method
call and send it to the real proxy if the JIT compiler inlined the method?
It is here that MarshalByRefObject comes to the rescue. To ensure that all
method calls are intercepted by the transparent proxy you inherit from
MarshalByRefObject. Hope this makes things clearer.
That says that preventing inlining is (currently) required in order to
meet the primary purpose of MarshalByRefObject. That's *very* different
from justifying your claim that the primary purpose of
MarshalByRefObject *is* to prevent inlining.

To make a comparison, imagine we were talking about ref parameters -
it's necessary for the types to match exactly (instead of being able to
pass a string for an object parameter, for example) - but it would be
laugable to state that the primary purpose of ref parameters was to
force people to use an argument of the *exact* type.
Put it this way - consider someone who has decided to derive from
MarshalByRefObject. When you ask them why they did so, do you think
it's likely that they'll reply "To prevent inlining" or "To enable
remoting/cross-app-domain calls (etc)"?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 7 '07 #15
On May 7, 11:47 am, "Kjetil" <kjetil[ANTI-SPAM]@kjetil.infowrote:
You are mistaken.

The MarshalByRefObject has a bad name. It's primary purpose is to supress
inlining by the JIT compiler so that the transparent proxy can do it's job.
The JIT compiler checks to see if a class inherits from MarshalByRef object
and don't inline if it does.
Interesting how nowhere in the MarshalByRefObject MSDN pages does it
state this. In fact, it directly supports what Jon says.

May 7 '07 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Tony Vitonis | last post by:
From what I can tell, VB.NET doesn't allow programmers to say explicitly that they want a function to be inlined. Now, I'm a big fan of factoring out duplicate code, but I don't want to do too...
6
by: glen_stark | last post by:
Hi. I'm just curious if there any warnings or caveats or whatever to be aware of when inlining function object calls? If the answer is no, they inline just like everything else, that's good...
10
by: gianguz | last post by:
The question is about the possible use of inlining to improve performance in a heavy multithreading environment (200+ threads). If we have to work with applications in which threads aren't I/O...
5
by: Raphael | last post by:
Hello, I have 2 files A.c : Defining a bunch of usefull functions B.c : Defining a main that uses these ones. I need to improve perfs : I know that, if the caller and the functions called...
11
by: Elpoca | last post by:
Hi: What rules govern the inlining of templated functions and templated class methods? It has always been my understanding that both templated functions and templated class methods were...
21
by: LuB | last post by:
How judicious ought one be when inlining small methods. I once read that in general, most compiles will only inline 'one' level. IE: if all the following methods were declared/defined as...
21
by: Michael Hull | last post by:
Hi, I remember from somewhere reading that inlining constructors is a 'BadThing', but now can't seem to find the original source. I can't however thing of a reason why it would be for simple...
8
by: Yakov | last post by:
I'd like a tool that performed inlining of function bodies of which do not appear in the .h file. Really. gcc on Linux. Yakov
58
by: sh.vipin | last post by:
is there any way to find out number of bytes freed on a particular free() call in C
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.