thrust::return_temporary_buffer

Defined in thrust/memory.h

template<typename DerivedPolicy, typename Pointer>
void thrust::return_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy> &system, Pointer p, std::ptrdiff_t n)

return_temporary_buffer deallocates storage associated with a given Thrust system previously allocated by get_temporary_buffer.

Thrust uses return_temporary_buffer internally when deallocating temporary storage required by algorithm implementations.

The following code snippet demonstrates how to use return_temporary_buffer to deallocate a range of memory previously allocated by get_temporary_buffer.

#include <thrust/memory.h>
...
// allocate storage for 100 ints with thrust::get_temporary_buffer
const int N = 100;

using ptr_and_size_t = thrust::pair<
  thrust::pointer<int,thrust::device_system_tag>,
  std::ptrdiff_t
>;

thrust::device_system_tag device_sys;
ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);

// manipulate up to 100 ints
for(int i = 0; i < ptr_and_size.second; ++i)
{
  *ptr_and_size.first = i;
}

// deallocate storage with thrust::return_temporary_buffer
thrust::return_temporary_buffer(device_sys, ptr_and_size.first);

See also

free

See also

get_temporary_buffer

Parameters
  • system – The Thrust system with which the storage is associated.

  • p – A pointer previously returned by thrust::get_temporary_buffer. If ptr is null, return_temporary_buffer does nothing.

Template Parameters

DerivedPolicy – The name of the derived execution policy.

Pre

p shall have been previously allocated by thrust::get_temporary_buffer.