473,385 Members | 1,693 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,385 software developers and data experts.

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

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

Apr 28 '07 #1
4 2051
You have to apply the MethodImpl attribute, with
MethodImplOptions.NoInlining specified.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
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

Apr 28 '07 #2
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

ZCan I force a function to NEVER be inlined?
Z>
ZI want the call stack returned by:
ZSystem.Diagnostics.StackTrace callStack = new
ZSystem.Diagnostics.StackTrace();
Zto be such that:
ZSystem.Diagnostics.StackFrame frame = callStack.GetFrame(0);
Zis the function itself, NOT the function's caller (due to a release
Zbuild making the function inlined into its caller)!
Zthanks!
Z>
ZZytan
Z>
Apr 28 '07 #3
You have to apply the MethodImpl attribute, with
MethodImplOptions.NoInlining specified.
Wow, so you can! thanks, Nicholas!

Zytan

Apr 30 '07 #4
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

Apr 30 '07 #5

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

Similar topics

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...
4
by: Ovidesvideo | last post by:
Just a quick question. If I declare functions in the class declaration as such: class myclass { public: void function(int &x) { x++; } };
8
by: Mat Booth | last post by:
If I call an inline member function through a member function pointer, will that function be inlined? I imagine it wouldn't because the function that's pointed to isn't known until run-time, is...
43
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
5
by: publictom | last post by:
I just happened to read item 47, "Control Flow", in Exceptional C++ by Herb Sutter (which is based on Guru of the Week 12), just after reading item 33, "Use Inlining Judiciously", in Effective C++...
6
by: Sharon | last post by:
Usually it is common to write the class member function in the class H file, but some people like to write the function body in the C++ file. Can anybody tell me what are the cases where inline...
7
by: ypjofficial | last post by:
Hello All, Inline before a function definition is just a request to the compiler to make the function inline. The compiler may or maynot make it inline.. My question is ..is there any way by...
14
by: jg | last post by:
Does C++ standard require an inline function be generated all the time ? For example, #include <iostream> using namespace std; inline int foo() {
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.