Thursday, October 22, 2009

ATL Removal: Part 2 – Safely Deleting ATL_NO_VTABLE

As I was going through and purging ATL from my project, I ran into the macro ATL_NO_VTABLE. It appears that some ATL project generators slap that baby into your class definition.

class ATL_NO_VTABLE CYourClass :…

It turns out that it is an optimization “that prevents the vtable pointer from being initialized in the class's constructor and destructor. If the vtable pointer is prevented from being initialized in the class's constructor and destructor, the linker can eliminate the vtable and all of the functions to which it points. Expands to __declspec(novtable).”

It sounds like a good optimization for ATL code since your object will be wrapped by CComObject anyway; however, with normal com code, having the vtable line up with IUnknown is important. In turning your ATL com object into to a regular com object, it is safe to just remove ATL_NO_VTABLE.

No comments:

Post a Comment