Friday, February 23, 2007 4:49 PMCould you make an unmanaged c++ dll and put some assembly functions in it then use those from inside c# through that dll? Would you have to marshall the stuff in with interop or no? would you actually gain speed by doing this? I dont actually need to do this im just curious in case I need it someday.
Saturday, February 24, 2007 12:17 AMWriting CIL in C# is similar to writing assembly in C++. if you want to optimze your C# speed as much as possible in some extreme cases, look into CIL programming instead. As speed will be critical, and each interop calls come with performance penalty, using unmaged C++ in C# may don't buy you much, even if the C++ code uses assembly functions.
Saturday, February 24, 2007 3:00 AMModerator
Any time you need to go from managed to unmanaged code will have a performance penalty. Since C++ can compile into mixed mode assemblies it is possible to place assembly (x86) code into an assembly and use that assembly from C# as long as it exposes methods to use in a compliant way.
If inline x86 will actually improve performance is something you only can answer after doing tests. What I have seen so far most performance improvements are done with resource management as any code accessing external resources usually is what degrades performance.
There might be some penalties in using a a mixed mode C++ class library and you will have to compare it to whatever processing you need to do.
Tuesday, July 29, 2008 10:17 AMIt is now possible with the opensource project NetAsm. This library enables you to inline x86 assembler code inside any .NET language...
Currently, NetAsm doesn't provide any keyword __asm to facilitate x86 assembler integration but it could be supported in the future. Therefore, you have to copy the binary representation of your textual x86 assembler (you can get such binary from an assembler, or from Visual C++ and configuring “Generate assembler source file” and use *.cod files)