共用方式為


return_temporary_buffer

將使用 get_temporary_buffer 樣板函式配置的暫存記憶體取消配置。

template<class Type> 
   void return_temporary_buffer( 
      Type* _Pbuf 
   );

參數

  • _Pbuf
    為記憶體指標解除配置。

備註

應該是暫時的記憶體才會使用這個函式。

範例

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

   int* tempBuffer = resultPair.first;

   // Deallocates memory allocated with get_temporary_buffer
   return_temporary_buffer ( tempBuffer );
}
  

需求

標頭: <memory>

命名空間: std