Compartilhar via


CHeapPtr::Allocate

Call this method to allocate memory on the heap to store objects.

bool Allocate( 
   size_t nElements = 1  
) throw( );

Parameters

  • nElements
    The number of elements used to calculate the amount of memory to allocate. The default value is 1.

Return Value

Returns true if the memory was successfully allocated, false on failure.

Remarks

The allocator routines are used to reserve enough memory on the heap to store nElement objects of a type defined in the constructor.

Example

// Create a new CHeapPtr object
CHeapPtr <int> myHP;
// Allocate space for 10 integers on the heap
myHP.Allocate(10);

Requirements

Header: atlalloc.h

See Also

Reference

CHeapPtr Class

CHeapPtr::Reallocate