Search code examples
c++performancestackunmanagedmanaged

Unmanaged within Managed Vs. Pure unmanaged


Will Unmanaged code (CPP) operated by Managed code (C#) have the same preformance as if it was operated by another unmanaged code (does the stack operate the same etc)?

I.e. - If I call code in MyCppApp from MyCs will it have the same performance as if it was called from MyCpp2App?

I am aware of the toll of the interop actions, but leaving those aside, My question is on performance of the CPP code execution itself.

Thanks, S


Solution

  • Once control is in unmanaged code the fact that is called by managed code does not have any influence over what the CPU does. The CPU executes the same instructions regardless of the caller. In fact the CPU has no notion of a "caller".

    Therefore performance is the same no matter who calls a piece of code. (Assuming, calling costs are zero.)