Summary
ATL provides a rich set of classes for
manipulating the data types COM programmers frequently use. The
CComVariant class provides practically the same benefits
as the CComBSTR class, but for VARIANT
structures. If you use a VARIANT structureand you will
need to use one sooner or lateryou should instead use the ATL
CComVariant smart VARIANT class. You'll have far
fewer problems with resource leaks.
SAFEARRAYs have a number of specialized
semantics as well. CComSafeArray was shown to be a useful
template class for managing both single- and multidimensional
SAFEARRAYs. As with other managed resources, however, take
care when dealing with CComSafeArray because the compiler
cannot always tell you if you've written code that will result in a
memory leak.
The CComPtr, CComQIPtr, and
CComGITPtr smart pointer classes ease, but do not totally
alleviate, the resource management needed for interface pointers.
These classes have numerous useful methods that let you write more
application code and deal less with the low-level
resource-management details. You'll find smart pointers most useful
when you're using interface pointers with exception handling.
Finally, you can control memory management in
ATL with IAtlMemMgr and five concrete implementations that
are supplied: CWin32Heap, CComHeap,
CCRTHeap, CLocalHeap, and CGlobalHeap.
You can program ATL classes such as CString to use memory
from these heaps or even from a custom implementation of
IAtlMemMgr, to provide a high degree of control and
facilitate any number of performance optimizations.
|