IAtlMemMgr, classe

Cette classe représente l'interface à un gestionnaire de mémoire.

__interface __declspec( uuid( "654F7EF5-CFDF-4df9-A450-6C6A13C622C0" )) IAtlMemMgr

Membres

Méthodes

Allouez

Appelez cette méthode pour allouer un bloc de mémoire.

Free (libre)

Appelez cette méthode pour libérer un bloc de mémoire.

GetSize

Appelez cette méthode pour récupérer la taille d'un bloc de mémoire alloué.

Réaffectez

Appelez cette méthode pour réaffecter un bloc de mémoire.

Notes

Cette interface est implémentée par CComHeap, CCRTHeap, CLocalHeap, CGlobalHeap, ou CWin32Heap.

Notes

Les variables locales et les fonctions globales du tas sont plus lents que d'autres fonctions de gestion de la mémoire, et ne fournissent pas autant de fonctionnalités.Par conséquent, les nouvelles applications doivent utiliser fonctions du tas.Ce sont disponibles dans la classe de CWin32Heap .

Exemple

// 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;
}

Configuration requise

Header: atlmem.h

Voir aussi

Autres ressources

Vue d'ensemble de la classe ATL