Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Allocates temporary storage for a sequence of elements that does not exceed a specified number of elements.

template<class Type>
   pair<Type *, ptrdiff_t>
         ptrdiff_t _Count


The maximum number of elements requested for which memory is to be allocated.

A pair whose first component is a pointer to the memory that was allocated, and whose second component gives the size of the buffer, indicating the largest number of elements that it could store.

The function makes a request for memory and it may not succeed. If no buffer is allocated, then the function returns a pair, with the second component equal to zero and the first component equal to the null pointer.

This function should only be used for memory that is temporary.

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

using namespace std;

int main( )
   // Create an array of ints
   int intArray [ ] = { 10, 20, 30, 40, 100, 200, 300, 1000, 2000 };
   int count = sizeof ( intArray ) / sizeof ( int );
   cout << "The number of integers in the array is: " 
      << count << "." << endl;

   pair<int *, ptrdiff_t> resultPair;
   resultPair = get_temporary_buffer<int>( count );

   cout << "The number of elements that the allocated memory\n"
        << "could store is given by: resultPair.second = " 
        << resultPair.second << "." << endl;
The number of integers in the array is: 9.
The number of elements that the allocated memory
could store is given by: resultPair.second = 9.

Header: <memory>

Namespace: std

Community Additions

© 2015 Microsoft