function template
<memory>
std::return_temporary_buffer
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.
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
|
// get/return_temporary_buffer example
#include <iostream>
#include <memory>
#include <algorithm>
int main () {
int numbers[] = {30,50,10,20,60,40};
// use temporary buffer to sort and show the numbers:
std::pair <int*,std::ptrdiff_t> result = std::get_temporary_buffer<int>(6);
if (result.second>0)
{
std::uninitialized_copy (numbers,numbers+result.second,result.first);
std::sort (result.first,result.first+result.second);
std::cout << "sorted numbers : ";
for (int i=0;i<result.second;i++)
std::cout << result.first[i] << " ";
std::cout << '\n';
std::return_temporary_buffer (result.first);
}
// show original numbers:
std::cout << "unsorted numbers: ";
for (int i=0;i<6;i++)
std::cout << numbers[i] << " ";
std::cout << '\n';
return 0;
}
|
Possible output:
sorted numbers : 10 20 30 40 50 60
unsorted numbers: 30 50 10 20 60 40
|