I'm coding a DLL for C# as a high-performance-module so I use C++/CLI because it's easy to referred in C# and supports native code. I found on msdn that using #pragma managed(push, off) and #pragma managed(pop) could make codes in it compiled as native code. But according to my simple test, the result was showing contrary.
Here's the code, compiled with /clr using Visual Studio 2012.
int clrloop() { for (int i = 0; i < 999999999; i++) { double test=9.999; test=pow(test, 10); } return 0; } #pragma managed(push,off) int loop() { for (int i = 0; i < 999999999; i++) { double test=9.999; test=pow(test, 10); } return 0; } #pragma managed(pop) int main(array<System::String ^> ^args) { int a=loop(); int b=clrloop(); return 0; }
Performance analysis showed that the unmanaged loop() cost twice to clrloop(). But if I put the loop() into different .cpp file and set this single file compiled wihouth /clr, and without any use of #pragma managed(push, off) things, the result was good as expected.
So, what's the problem with this #pragma?