Being Bit(ten) and Byting Back

Thursday, April 28, 2005

So what's a POD in Managed C++??

While reviewing some documentation on Managed C++ I came across the word POD. I knew that it meant Plain Old Datatype and by definition, a POD is a datatype that can be copied by copying its bits and does not need a constructor. Digging it a little more I came across this Q & A article by Paul DiLascia. From what I understood , a POD in .Net is restricted in managed C++ classes because the framework then copy these datatypes without worrying about constructors, vtables, etc. Read more about it here I also came across about an interesting difference between C++ and C#. In C++, its generally regarded as bad practice to call virtual functions, in constructors and destructors. The reason is that, during the construction of a derived object, the constructor of the base class is run first, and hence would call the virtual function (if called) implemented in the base class instead of the one overridden in the derived class. On the other hand in C#, the virtual function in the derived class will be called as intended. The reason for this is that when the constructor in a C# object is called, the object is completely constructed. The reason for this behavior is because of the garbage collector. To optimize the performance of the garbage collector, the size of the objects should be known a-priori. And to know the size of the object a-priori, its necessary to construct the complete object (instantiate derived and any base classes). Read a more detailed explanation here.

0 Comments:

Post a Comment

<< Home