A few years ago I was working on a project that was converting an enterprise business application from being compiled in unmanaged C++ to compiling it in managed C++. The purpose was to get it running on the CLR to expose it for integration with other .Net projects we were working on that were using C#. One of the issues with converting an existing C++ application to build on the .Net Framework is the problem known as a double thunk. A double thunk occurs when program execution hops from managed code to native code and then back to managed code. Why is it an issue? You take a performance hit each time you switch from managed to unmanaged code or vice versa. And with a double thunk you get hit twice. In managed C++ this happens with function pointers and calling virtual functions. However there is a C++ keyword you can use __clrcall to fix the issue. Check out this MSDN article for more information on it.
To help track down those issues I developed an FxCop rule to check for these double thunks. This rule works on the FxCop 1.35 version. I have includes a zip file of the source code for this rule and provided a link to it at the bottom of this post. In that project are references to two assemblies from FxCop. So if you decide to upgrade to newer versions of FxCop you would probably need to replace those assemblies. Anyways, assuming FxCop 1.35, once you build the code you just need to copy the resulting assembly to the Rules folder of the FxCop install location. FxCop will then be able to load and use the rule from that location.
I have verified this rule works with the C++ example in the MSDN article I referred to earlier.
Double Thunk Rule zip file
Friday, February 20, 2009
FxCop Double Thunk Rule
Posted by
K Jacobson
at
7:58 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment