Template Function thrust::return_temporary_buffer

Function Documentation

template<typename DerivedPolicy, typename Pointer>__host__ __device__ void thrust::return_temporary_buffer(const thrust::detail::execution_policy_base< DerivedPolicy > & system, Pointer p)

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.
Pre

p shall have been previously allocated by thrust::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.

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

typedef thrust::pair<
  thrust::pointer<int,thrust::device_system_tag>,
  std::ptrdiff_t
> ptr_and_size_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

free

See

get_temporary_buffer