get_temporary_buffer

分配权限不超过指定数量的元素的元素序列的临时存储。

template<class Type>
   pair<Type *, ptrdiff_t>
      get_temporary_buffer(
         ptrdiff_t _Count
      );

参数

  • _Count
    将哪内存请求的元素的最大数目。

返回值

第一个元素是指向内存分配,因此,第二个元素提供的缓冲区的大小,指示元素的大量它所能存储的 pair

备注

函数创建一个内存要求,可能会失败。如果未分配缓冲区,则该函数返回对,与第二个元素等于零和第一个元素等于null指针。

应是瞬态的内存才使用此功能。

示例

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

要求

标头: <memory>

命名空间: std