IAtlMemMgr选件类
此选件类表示界面内存管理器。
__interface __declspec( uuid( "654F7EF5-CFDF-4df9-A450-6C6A13C622C0" )) IAtlMemMgr
成员
方法
调用此方法分配内存块。 |
|
调用此方法可释放内存块。 |
|
调用此方法检索分配的内存块范围。 |
|
调用此方法分配内存块。 |
备注
此接口由 CComHeap、 CCRTHeap、 CLocalHeap、 CGlobalHeap或 CWin32Heap实现。
备注
本地资源文件和全局堆函数比其他内存管理函数慢不提供了多种功能。因此,新应用程序应使用 堆函数。这些可在 CWin32Heap 选件类。
示例
// Demonstrate IAtlMemMgr using the five possible
// memory function implementation classes.
HRESULT MemoryManagerDemonstration(IAtlMemMgr& MemoryManager) throw()
{
// The IAtlMemMgr interface guarantees not to throw exceptions
// so we can make the same guarantee for this function
// without adding exception handling code.
// A variable which will point to some allocated memory.
void* pMemory = NULL;
const size_t BytesInChunk = 1024;
// Allocate a chunk of memory
pMemory = MemoryManager.Allocate(BytesInChunk);
// Confirm the validity of the allocated memory
if (pMemory == NULL)
return E_OUTOFMEMORY;
// Confirm the size of the allocated memory
ATLASSERT(MemoryManager.GetSize(pMemory) == BytesInChunk);
// Increase the size of the allocated memory
pMemory = MemoryManager.Reallocate(pMemory, BytesInChunk * 2);
// Confirm the validity of the allocated memory
if (pMemory == NULL)
return E_OUTOFMEMORY;
// Confirm the size of the reallocated memory
ATLASSERT(MemoryManager.GetSize(pMemory) == BytesInChunk * 2);
// Free the allocated memory
MemoryManager.Free(pMemory);
return S_OK;
}
int DoMemoryManagerDemonstration()
{
CComHeap heapCom;
CCRTHeap heapCrt;
CLocalHeap heapLocal;
CGlobalHeap heapGlobal;
// It is necessary to provide extra information
// to the constructor when using CWin32Heap
CWin32Heap heapWin32(NULL, 4096);
ATLASSERT(S_OK==MemoryManagerDemonstration(heapCom));
ATLASSERT(S_OK==MemoryManagerDemonstration(heapCrt));
ATLASSERT(S_OK==MemoryManagerDemonstration(heapLocal));
ATLASSERT(S_OK==MemoryManagerDemonstration(heapGlobal));
ATLASSERT(S_OK==MemoryManagerDemonstration(heapWin32));
return 0;
}
要求
Header: atlmem.h