allocator::allocate
Visual Studio 2012
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 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