inline functions

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

How do I write an inline function in c#? I've tried and looked at tutorials
and other stuff but haven't been able to figure it out. if someone could
give me a blank example, that would be very nice. thanks
dave
 
Keep the size under 32 or else just code it inline. as you go no say in this
:D

Microsoft knows better than you apparently :D
 
an in line function is a function that just holds code. and when you put it
into your code, the compiler basically replaces the function call with the
code in side the function.
 
so you're saying they don't exist in c#? I could copy and paste the function
in like you said but I want to do it so many times and right after each
other that I thought it would make things easier to just use an inline
funciton many times. it would make it much easier to maintain as well. if
you're wondering, its for a time consuming program that has a loop and I
don't want to look after each call of the function, I need it to basically
run the function inside of the loop a few times or so before the while is
done again. just trust me that that's what I really want.
thanks
dave
 
Dave said:
so you're saying they don't exist in c#? I could copy and paste the function
in like you said but I want to do it so many times and right after each
other that I thought it would make things easier to just use an inline
funciton many times. it would make it much easier to maintain as well. if
you're wondering, its for a time consuming program that has a loop and I
don't want to look after each call of the function, I need it to basically
run the function inside of the loop a few times or so before the while is
done again. just trust me that that's what I really want.
thanks

Well, that is both inlining AND loop unrolling. I imagine the JIT does some
loop unrolling, and I know it inlines, but it is up to the JITer, not the
coder to determine that.
 
Dave said:
so you're saying they don't exist in c#?

No, but you can't force them by declaring a function __inline or
whatever. It's dependent on the function size.
 
Alvin Bruney said:
Keep the size under 32 or else just code it inline. as you go no say in this
:D

Microsoft knows better than you apparently :D

I don't speak for Microsoft, but I would expect that the JIT compiler would
know better than you (or would have the capability to know as it matures)
when inlining would help vs. when it would hurt. Even in C++, most compilers
are free to ignore the inline keyword and do whatever they think is best
anyway.

I found this page to be an interesting overview of some issues associated
with inline functions.
http://www.parashift.com/c++-faq-lite/inline-functions.html

And in today's age of rapid-development languages, I'm thankful to not have
to worry about those issues as I try to decide what to inline.

Mike
 
The JIT has no ****in clue what my situation is has it, it has no ****in
clue how I ME MOI want MY program to run.
 
You could probably write a medium-complexity VS.NET macro to do it, then
just run that macro in the build event of your project. In the world of C#
inlining per se is the domain of the JIT compiler, as others have mentioned.

Richard
 
Back
Top