Here is some code the provides some really interesting results! First, read
over the two methods in class 'A' and compare. Just by looking at them,
both results appear to return the EXACT same information the same way. But
the appearances are deceiving! Copy and paste into a console application,
then set the configuration to Release mode :)
using System;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(A.DoIt1());
Console.WriteLine(A.DoIt2());
}
}
public class A
{
public static string DoIt1()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
return method.Name;
}
public static string DoIt2()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
int i = 0; i++;
return method.Name;
}
}
}
Very interesting ... anywho, comments or explanations? :)
Mythran 8 7935
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote: Here is some code the provides some really interesting results!
[snip] Very interesting ... anywho, comments or explanations? :)
What you're seeing is inlining. Stack traces in release mode don't
necessarily reflect the true sequence of calls. If any of the stack
frames include code access security attributes, or if they are
moderately complex, then they won't be inlined.
-- Barry
-- http://barrkel.blogspot.com/
On Tue, 23 May 2006 15:01:22 -0700, Mythran wrote: Here is some code the provides some really interesting results! First, read over the two methods in class 'A' and compare. Just by looking at them, both results appear to return the EXACT same information the same way. But the appearances are deceiving! Copy and paste into a console application, then set the configuration to Release mode :)
[...] Very interesting ... anywho, comments or explanations? :)
That looks surpring indeed. I suppose that when compiling in Release mode,
the JIT compiler must do some optimization such as inlining the call to
DoIt1, hence the result.
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:4l********************************@4ax.com... "Mythran" <ki********@hotmail.comREMOVETRAIL> wrote:
Here is some code the provides some really interesting results! [snip] Very interesting ... anywho, comments or explanations? :)
What you're seeing is inlining. Stack traces in release mode don't necessarily reflect the true sequence of calls. If any of the stack frames include code access security attributes, or if they are moderately complex, then they won't be inlined.
-- Barry
-- http://barrkel.blogspot.com/
And I don't have code access security attributes applied, and I don't see
how i++ is even considered complex at all...the only difference in the two
methods is one having an "int i = 0; i++;" and the other doesn't...yet the
results of the trace is different...
Mythran
Mythran,
What is so interesting
I get the exact result expected,
DoIt1
DoIt2
To really see result use
Console.WriteLine(A.DoIt1());
Console.WriteLine(A.DoIt2());
Console.ReadLine();
Sa
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl... Here is some code the provides some really interesting results! First, read over the two methods in class 'A' and compare. Just by looking at them, both results appear to return the EXACT same information the same way. But the appearances are deceiving! Copy and paste into a console application, then set the configuration to Release mode :)
using System; using System.Diagnostics; using System.Reflection;
namespace ConsoleApplication1 { class Class1 { [STAThread] static void Main(string[] args) { Console.WriteLine(A.DoIt1()); Console.WriteLine(A.DoIt2()); } }
public class A { public static string DoIt1() { StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(0); MethodBase method = frame.GetMethod(); return method.Name; } public static string DoIt2() { StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(0); MethodBase method = frame.GetMethod(); int i = 0; i++; return method.Name; } } }
Very interesting ... anywho, comments or explanations? :)
Mythran
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote: And I don't have code access security attributes applied, and I don't see how i++ is even considered complex at all...the only difference in the two methods is one having an "int i = 0; i++;" and the other doesn't...yet the results of the trace is different...
Basically, you can't rely on whether or not inlining occurs. That's
about all you can say.
-- Barry
-- http://barrkel.blogspot.com/
"msdn" <sq**********@hotmail.com> wrote: What is so interesting
I get the exact result expected, DoIt1 DoIt2
Did you compile in both release and debug mode? Or alternatively, on the
command line, try 'csc /optimize+' versus 'csc /optimize-'.
-- Barry
-- http://barrkel.blogspot.com/
Yes I did in both ways (release and debug) and in both ways I got the same
result.
Sa
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:0j********************************@4ax.com... "msdn" <sq**********@hotmail.com> wrote:
What is so interesting
I get the exact result expected, DoIt1 DoIt2
Did you compile in both release and debug mode? Or alternatively, on the command line, try 'csc /optimize+' versus 'csc /optimize-'.
-- Barry
-- http://barrkel.blogspot.com/
"msdn" <sq**********@hotmail.com> wrote: Yes I did in both ways (release and debug) and in both ways I got the same result.
And you ran both on the command line (i.e. outside the IDE, so the
debugger isn't attached), on .NET 2.0? Interesting.
-- Barry
-- http://barrkel.blogspot.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lord Bah |
last post by:
I've seen some other posts referring to this problem, but didn't find
any solutions.
We're trying to log a call stack when we have a problem, using the
StackTrace and StackFrame classes in C#....
|
by: Avinash |
last post by:
Hi,
I am facing problem with the use of the stackframe and stacktrace for the
exception hadling with Windows service.
Can any one please tell me how to use of the above objects (stackframe and...
|
by: scottrm |
last post by:
I am using StackFrame class to retrieve File Name and File Line number for
printing out into the debug file.
Everything is working under Debug build. However StackFrame doesn't capture
File Name...
|
by: Ben Fidge |
last post by:
Hi
When my ASP.NET application traps an exception, it's details and the call
stack are written to a log, but for some reason, StackFrame.GetFileName()
always returns null. This is when running...
|
by: Joe Rattz |
last post by:
Moved some asp.net code using StackFrame (built in debug mode) to a Windows
Server 2003 box and get empty filename and filelinenumber back. Anyone know
why? Works just fine on Win2k.
|
by: HCF_15 |
last post by:
Hi all,
I have a small piece of code to use StackFrame to GetMethod, I found it is
inconsistent in Debug version and Release version, is there anything I am
doing wrong?
Here is code, build in...
|
by: newscorrespondent |
last post by:
I have compiled in DEBUG mode but don't get the debug information from
StackFrame class. Is there a specific setting I need to use so that
information is included for a debug build.
Thanks
Tom
|
by: Gerrit Beuze |
last post by:
Hi all,
I'd like to get at the real underlying type when using the EnvDTE.Debugger
Currently I do this:
EnvDTE.Thread thread = dte.Debugger.CurrentThread;
foreach (StackFrame frame in...
|
by: Ryanivanka |
last post by:
hi,
is the stackframe in managed code the same as in unmanaged?
or they are not related at all.... :)
if I use some asm codes (get the esp register or something about
stackframe) in a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |