This is really an Adam Nathan kind of question but I'll over my limited observations and guesses and maybe he'll pop along-). As I understand it, any kind of Interop layer, whether it be wrapped MC++ classes, P/Invoke or COM Interop will require an "interoperability transition" to happen. This, of course, harkens back to the fact that the two sides of the boundary are different, right? The data types, structure layout, reference counting (not in managed code), memory schemes are all different. All of these things have to be "fixed" up by the Interop layer not to mention marshaling itself. All of this will cost you. Interop is not free. There's a whole level of indirection to go through.
In COM interop, its worse, especially with marshaling as there is a whole another layer involved. COM Interop must wrap the C++ class as well as generating the RCW wrapper. Now, of course, COM Interop is a complicated beast and there are hundreds of tweaks in the System::Runtime::InteropServices::Marshal and associated classes that can be made. I am not sure how you did your COM Interop, but as I understand it, out of the box, you will get late binding only (someone correct me if I am wrong). You have to do more to get it to perform better. For instance, marking the class with: [ClassInterface(ClassInterfaceType.AutoDual)] to generate a dual interface or whatever to get the early binding behavior. There are a lot of other things you can do. I would suggest looking at Adam Nathan's book for detailed explanations. >From: "Sills, Adam" <[EMAIL PROTECTED]> >Reply-To: dotnet discussion <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: [DOTNET] VB6 -> .NET interop slow? >Date: Fri, 12 Apr 2002 13:34:18 -0400 > >Okay here's the (quick) setup: > >We had a very fundamental vb dll, that was the core to the majority of our >business logic. It's not a very complex set of classes, and could have been >much more functional (and better) in another language that supported OO. >.Net comes along and we are trying to transition away from new development >in VB to new development in C#. This means that we have a couple choices >for >our core set of classes: > >1. Simply use COM interop to reference the vb dll and extend from there. >2. Rewrite in C# (not very long to do) and maintain two sets of code. >3. Rewrite in C# and turn the vb classes into a wrapper for the appropriate >C# classes. > >We chose #3, and the way it works is incredibly simple: > >* C# classes >* C# "interop" class, that is responsible for creating and returning >references to the appropriate C# classes (because I don't want public >default constructors when they don't make sense). >* VB classes have an instance of the interop class (actually it's a global >module-level variable), and then each class contains a reference to the >appropriate C# class, forwarding all method and property calls to the >appropriate method and property. The references to the C# classes in VB are >declared as Objects. > >Everything went very smooth until it got to the point of performance >testing. The .NET classes by themselves are fast. Fast as one would expect >them to be. However, when the layer of interop is added, they are >SLOOOOOWWWW. Roughly 4x slower than the VB-only version. Now, I initially >assumed it was that I hadn't generated a type library and "early bound" my >Object variables to the appropriate types. So I exported the typelib, no >more CreateObject, etc, and it's still slow (no visible improvement). I've >been through the MSDN docs on interop and can't find anything that seems >really important that I haven't done. > >Anyone have any thoughts or suggestions? > >You can read messages from the DOTNET archive, unsubscribe from DOTNET, or >subscribe to other DevelopMentor lists at http://discuss.develop.com. --------------------- Sam Gentile .NET Consultant Co-author: Wrox Visual C++ .NET: A primer for C++ developers BLOG: http://radio.weblogs.com/0105852/ http://www.project-inspiration.com/sgentile/DotNet.htm http://www.project-inspiration.com/sgentile/ --------------------------- _________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.