return_temporary_buffer
function template
<memory>
template <class T> void return_temporary_buffer (T* p);
Return block of temporary memory
Releases the memory block pointed by p.
p shall be a pointer value returned by a previous call to get_temporary_buffer.
Parameters
- p
- Pointer to a block of temporary memory returned by a previous call to get_temporary_buffer.
Return value
none
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// get/return_temporary_buffer example
#include <iostream>
#include <memory>
#include <algorithm>
using namespace std;
int main () {
int numbers[]= {30,50,10,20,60,40};
// use temporary buffer to sort and show the numbers:
pair <int*,ptrdiff_t> result = get_temporary_buffer<int>(6);
if (result.second>0)
{
uninitialized_copy (numbers,numbers+result.second,result.first);
sort (result.first,result.first+result.second);
cout << "sorted numbers : ";
for (int i=0;i<result.second;i++)
cout << result.first[i] << " ";
cout << endl;
return_temporary_buffer (result.first);
}
// show original numbers:
cout << "unsorted numbers: ";
for (int i=0;i<6;i++)
cout << numbers[i] << " ";
cout << endl;
return 0;
}
|
Possible output:
sorted numbers : 10 20 30 40 50 60
unsorted numbers: 30 50 10 20 60 40
|
See also
|