description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CHeapPtrBase class |
CHeapPtrBase class |
11/04/2016 |
|
|
501ac1b2-fb34-4c72-b7e6-a4f1fc8fda21 |
This class forms the basis for several smart heap pointer classes.
Important
This class and its members cannot be used in applications that execute in the Windows Runtime.
template <class T, class Allocator = CCRTAllocator>
class CHeapPtrBase
T
The object type to be stored on the heap.
Allocator
The memory allocation class to use. By default CRT routines are used to allocate and free memory.
Name | Description |
---|---|
CHeapPtrBase::~CHeapPtrBase |
The destructor. |
Name | Description |
---|---|
CHeapPtrBase::AllocateBytes |
Call this method to allocate memory. |
CHeapPtrBase::Attach |
Call this method to take ownership of an existing pointer. |
CHeapPtrBase::Detach |
Call this method to release ownership of a pointer. |
CHeapPtrBase::Free |
Call this method to delete an object pointed to by a CHeapPtrBase . |
CHeapPtrBase::ReallocateBytes |
Call this method to reallocate memory. |
Name | Description |
---|---|
CHeapPtrBase::operator T* |
The cast operator. |
CHeapPtrBase::operator & |
The & operator. |
CHeapPtrBase::operator -> |
The pointer-to-member operator. |
Name | Description |
---|---|
CHeapPtrBase::m_pData |
The pointer data member variable. |
This class forms the basis for several smart heap pointer classes. The derived classes, for example, CHeapPtr
and CComHeapPtr
, add their own constructors and operators. See these classes for implementation examples.
Header: atlcore.h
Call this method to allocate memory.
bool AllocateBytes(size_t nBytes) throw();
nBytes
The number of bytes of memory to allocate.
Returns true if the memory is successfully allocated, false otherwise.
In debug builds, an assertion failure will occur if the CHeapPtrBase::m_pData
member variable currently points to an existing value; that is, it's not equal to NULL.
Call this method to take ownership of an existing pointer.
void Attach(T* pData) throw();
pData
The CHeapPtrBase
object will take ownership of this pointer.
When a CHeapPtrBase
object takes ownership of a pointer, it will automatically delete the pointer and any allocated data when it goes out of scope.
In debug builds, an assertion failure will occur if the CHeapPtrBase::m_pData
member variable currently points to an existing value; that is, it's not equal to NULL.
The destructor.
~CHeapPtrBase() throw();
Frees all allocated resources.
Call this method to release ownership of a pointer.
T* Detach() throw();
Returns a copy of the pointer.
Releases ownership of a pointer, sets the CHeapPtrBase::m_pData
member variable to NULL, and returns a copy of the pointer.
Call this method to delete an object pointed to by a CHeapPtrBase
.
void Free() throw();
The object pointed to by the CHeapPtrBase
is freed, and the CHeapPtrBase::m_pData
member variable is set to NULL.
The pointer data member variable.
T* m_pData;
This member variable holds the pointer information.
The & operator.
T** operator&() throw();
Returns the address of the object pointed to by the CHeapPtrBase
object.
The pointer-to-member operator.
T* operator->() const throw();
Returns the value of the CHeapPtrBase::m_pData
member variable.
Use this operator to call a method in a class pointed to by the CHeapPtrBase
object. In debug builds, an assertion failure will occur if the CHeapPtrBase
points to NULL.
The cast operator.
operator T*() const throw();
Returns CHeapPtrBase::m_pData
.
Call this method to reallocate memory.
bool ReallocateBytes(size_t nBytes) throw();
nBytes
The new amount of memory to allocate, in bytes.
Returns true if the memory is successfully allocated, false otherwise.