Mixed mode C++/CLI performance considerations - best practices

前端 未结 1 1565
遥遥无期
遥遥无期 2021-01-25 09:34

I have a C++/CLI library that calls many native C++ methods. I have read many threads stating that you should not mix managed and unmanaged code. I couldnt find any that says ho

相关标签:
1条回答
  • 2021-01-25 10:09

    The only reason to use C++/CLI is for its support of mixing managed and native code. If everything is managed then use C# or VB, if everything is native then use C or C++. Or whatever language you prefer. Clearly avoiding mixing is nonsensical.

    There is a small amount of overhead going from managed to unmanaged. The C++/CLI compiler auto-generates a bit of machine code that pushes a 'cookie' on the stack, designed to prevent the garbage collector from blundering into unmanaged stack frames and mis-interpreting pointers on that frame as managed object references. Costs about 7 nanoseconds, give or take.

    0 讨论(0)
提交回复
热议问题