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