Reputation:
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
Upvotes: 3
Views: 92
Reputation: 2232
Yes, but keep in mind, that invoking the un-managed application may take longer, since data need to be copied from managed to un-managed buffers.
This is one of the issues with .NET and COM interop - the problem is in the number of instructions (~50) that have to be executed in order to get out of the managed environment - this making the whole process somewhat slow.
Also take not, that in the ultimate phase, managed code will be translated to appropriate machine code using JIT compilation.
Upvotes: 1
Reputation: 171178
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.)
Upvotes: 2