Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining


Allocates a block of memory large enough to store at least some specified number of elements.

pointer allocate(
   size_type _Count, 
   const void* _Hint


The number of elements for which sufficient storage is to be allocated.


A const pointer that may assist the allocator object satisfy the request for storage by locating the address of an object allocated prior to the request.

A pointer to the allocated object or null if memory was not allocated.

The member function allocates storage for an array of count elements of type Type, by calling operator new(_Count). It returns a pointer to the allocated object. The hint argument helps some allocators in improving locality of reference; a valid choice is the address of an object earlier allocated by the same allocator object and not yet deallocated. To supply no hint, use a null pointer argument instead.

// allocator_allocate.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>

using namespace std;

int main( ) 
   allocator<int> v1Alloc;

   allocator<int>::pointer v1aPtr;

   v1aPtr = v1Alloc.allocate ( 10 );

   int i;
   for ( i = 0 ; i < 10 ; i++ )
      v1aPtr[ i ] = i;

   for ( i = 0 ; i < 10 ; i++ )
      cout << v1aPtr[ i ] << " ";
   cout << endl;

   v1Alloc.deallocate( v1aPtr, 10 );
0 1 2 3 4 5 6 7 8 9 

Header: <memory>

Namespace: std

© 2015 Microsoft