Advantages and Disadvantages of Writing an Unmanaged Class LibraryIf you're writing a class library from scratch today, you might wonder whether you should write it in unmanaged C++. Well, that depends on what languages will be using it. If you plan to use the library extensively from Visual Basic .NET or C#, it's far better to write the library in managed C++ and take advantage of the language interoperability on the .NET Framework. If you plan to use the library mainly from existing unmanaged C++ applications, writing it in unmanaged C++ makes sense. You can use IJW to access it from managed C++. In general, unmanaged C++ is faster than managed C++. If you're writing a library where performance is very important, and the calculations are weighty enough that other languages might be slow, unmanaged C++ is the way to go. It's also more portable, allowing you to use the same code base to maintain a library for several different operating systems. Managed C++, Visual Basic .NET, and C# class libraries can be used only on systems where the .NET Framework has been installed. Unmanaged C++ libraries will work on a larger population of systems. Of course, the .NET Framework was invented for a reason. It brings simple interoperability, memory management, and consistent Rapid Application Development techniques to programmers in a variety of managed languages. When you look at the advantages of managed C++ over unmanaged C++, you might well choose to write in managed code. On every count except code execution speed, managed C++ is preferable. So if you're not counting CPU cycles, and you don't need to support any operating systems other than fairly recent versions of Windows, a managed class library is a better choice. The next chapter shows you how that's done. |