Peter's Gekko : May 2005 - Posts
Peter's Gekko : May 2005 - Posts:
C++ for .NET at dotned
Yesterday we had the VS 2005 C++ team at the dotned user group meeting. It was a good meeting and a good talk. Ronald Laeremans is somebody who can, and will, talk for hours. The C++ vision on .net is quite interesting, let me reproduce some of the things I learned.
To me the C++ language has always been one you had to learn to live with. Never did any real C++ programming but I had to read C++ on a daily basis. All code samples were in C++, incorporating the ideas in my Delphi win32 required translating. These days I do mainly C#, a language whose syntax is far closer to C++ than Object Pascal but whose “architecture” (events, properties, components) comes far closer to Delphi.
C++ is still a major language at MS, according to the VC team 95% of the MS products is coded in C ++. The team was clearly jealous on the new star C# but gave some good reasons to use (unmanaged) C++:
* Existing code base. You can’t dump 20 years of Windows and Office development
* Backward compatibilty.
* Do your own memory management. Some code has to keep running with 0% memory free. In managed code the smallest things, like boxing an integer, can result in a memory allocation (by the CLR)
* Directly invoking an unmanaged function is checked at compile time. A dllimport in managed code is checked at runtime.
The upcoming C++ does a couple of things to bring the world of unmanaged C++ and managed code together
* To the compiler IL is just another platform target, there’s x86, Itanium and IL
* When declaring a class in C++ you can prefix the class with the value or ref keyword. The class (type) will than be compiled into a managed class which can be reused by any .net language using the assemby. A class without a prefix is a native class.
* The clr:safe compiler directive checks your code on the absence of pointers and native classes. When both criteria are met you have a built a managed assembly with C++.
* A nice feature are trivial properties and events. Declared as a property but you don’t have to write out the (trivial) getter and setter routines.
Some nice scenarios of mixed code
* Wrap up DirectX complexities. Directly address DirectX objects iterated in a .net foreach loop.
* Give an MFC app a .NET Winforms UI. As a demonstration the team had built a customized slide sorter for Powerpoint. Powerpoint in an MFC app and Winforms is very good in building a sophisticated UI.
C++ is clearly not intended as a mainstream language. You can still do horrific things. And in your app you’re dealing with three kinds of memory: the stack, the managed heap and the native heap. Not for the faint of heart. I will stick to my beloved C# but have seen good things to further expand my horizon. (But will not forget pInvoke.net)
Another part of a meeting is the social networking part. Of course Sander and Hassan were there and I promissed to restore the broken links to their perfomaces on a former meeting. Is done. See you at the next meeting.
0 Comments:
Post a Comment
<< Home