G
Guest
Given a property define like this:
public decimal ControlAmount
{
get { return mControlAmount; }
set { mControlAmount = value; }
}
I expected (under release mode) that when used as a variable in normal code
(ie, nothing that is enumerating properties or requiring metadata) eg:
ControlAmount += MyValue;
That the get accessor would be "optimized out", and replaced with direct
access to the variable (like an "inline function"). This is what would have
happened in C++ or Delphi.
However, I am finding that this is not the case in my code, even in release
mode. I profile my application, and find that the get_ControlAmount function
not only gets called *all the time*, but that it has significant overhead -
much more so than a simple member variable access.
Is there any way to optimize simple properties like this, or ensure that the
optimizer is able to remove the call?
public decimal ControlAmount
{
get { return mControlAmount; }
set { mControlAmount = value; }
}
I expected (under release mode) that when used as a variable in normal code
(ie, nothing that is enumerating properties or requiring metadata) eg:
ControlAmount += MyValue;
That the get accessor would be "optimized out", and replaced with direct
access to the variable (like an "inline function"). This is what would have
happened in C++ or Delphi.
However, I am finding that this is not the case in my code, even in release
mode. I profile my application, and find that the get_ControlAmount function
not only gets called *all the time*, but that it has significant overhead -
much more so than a simple member variable access.
Is there any way to optimize simple properties like this, or ensure that the
optimizer is able to remove the call?