共用方式為


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