PC Review


Reply
Thread Tools Rate Thread

c# can you force a function to NOT be inlined?

 
 
Zytan
Guest
Posts: n/a
 
      28th Apr 2007
Can I force a function to NEVER be inlined?

I want the call stack returned by:
System.Diagnostics.StackTrace callStack = new
System.Diagnostics.StackTrace();
to be such that:
System.Diagnostics.StackFrame frame = callStack.GetFrame(0);
is the function itself, NOT the function's caller (due to a release
build making the function inlined into its caller)!

thanks!

Zytan

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      28th Apr 2007
You have to apply the MethodImpl attribute, with
MethodImplOptions.NoInlining specified.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Zytan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can I force a function to NEVER be inlined?
>
> I want the call stack returned by:
> System.Diagnostics.StackTrace callStack = new
> System.Diagnostics.StackTrace();
> to be such that:
> System.Diagnostics.StackFrame frame = callStack.GetFrame(0);
> is the function itself, NOT the function's caller (due to a release
> build making the function inlined into its caller)!
>
> thanks!
>
> Zytan
>



 
Reply With Quote
 
Michael Nemtsev
Guest
Posts: n/a
 
      28th Apr 2007
Hello Zytan,

Just to add to Nicholas, another inlining prerequisites are:
- methods are small (32bytes of IL),
- no virtual,
- simple control flow
- no try/catch
- no stuct for arguments or local.

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

Z> Can I force a function to NEVER be inlined?
Z>
Z> I want the call stack returned by:
Z> System.Diagnostics.StackTrace callStack = new
Z> System.Diagnostics.StackTrace();
Z> to be such that:
Z> System.Diagnostics.StackFrame frame = callStack.GetFrame(0);
Z> is the function itself, NOT the function's caller (due to a release
Z> build making the function inlined into its caller)!
Z> thanks!
Z>
Z> Zytan
Z>


 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      30th Apr 2007
> You have to apply the MethodImpl attribute, with
> MethodImplOptions.NoInlining specified.


Wow, so you can! thanks, Nicholas!

Zytan

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      30th Apr 2007
> Just to add to Nicholas, another inlining prerequisites are:
> - methods are small (32bytes of IL),
> - no virtual,
> - simple control flow
> - no try/catch
> - no stuct for arguments or local.


Ok, so I could use any one of these and it wouldn't be inlined. But,
it's likely best to just specify the attribute. Thanks, Michael

Zytan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to view that method is inlined? Michael Nemtsev Microsoft C# .NET 2 9th Jan 2006 11:03 PM
VC++2003: Methods implemented outside class body are never inlined for templates that are instantiated with __declspec(dllimport) Felix I. Wyss Microsoft VC .NET 5 16th Mar 2005 02:53 AM
Inlined functions in mixed mode C++ Steve McLellan Microsoft VC .NET 2 28th Jul 2004 03:19 PM
How Can I tell if my method has been inlined? FDude Microsoft Dot NET 1 14th Feb 2004 09:03 AM
Debug optimized code? (with inlined methods) Fuzzy Microsoft C# .NET 7 3rd Feb 2004 10:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:26 AM.