thrust
Functions
Deallocation Functions

Functions

template<typename T >
void thrust::device_delete (thrust::device_ptr< T > ptr, const size_t n=1)
 
void thrust::device_free (thrust::device_ptr< void > ptr)
 
template<typename DerivedPolicy , typename Pointer >
__host__ __device__ void thrust::free (const thrust::detail::execution_policy_base< DerivedPolicy > &system, Pointer ptr)
 
template<typename DerivedPolicy , typename Pointer >
__host__ __device__ void thrust::return_temporary_buffer (const thrust::detail::execution_policy_base< DerivedPolicy > &system, Pointer p)
 

Detailed Description

Function Documentation

template<typename T >
void thrust::device_delete ( thrust::device_ptr< T >  ptr,
const size_t  n = 1 
)
inline

device_delete deletes a device_ptr allocated with device_new.

Parameters
ptrThe device_ptr to delete, assumed to have been allocated with device_new.
nThe number of objects to destroy at ptr. Defaults to 1 similar to device_new.
See Also
device_ptr
device_new

Referenced by thrust::device_new_allocator< T >::deallocate().

void thrust::device_free ( thrust::device_ptr< void >  ptr)
inline

device_free deallocates memory allocated by the function device_malloc.

Parameters
ptrA device_ptr pointing to memory to be deallocated.

The following code snippet demonstrates how to use device_free to deallocate memory allocated by device_malloc.

...
// allocate some integers with device_malloc
const int N = 100;
thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
// manipulate integers
...
// deallocate with device_free
thrust::device_free(int_array);
See Also
device_ptr
device_malloc

Referenced by thrust::device_malloc_allocator< T >::deallocate().

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

free deallocates the storage previously allocated by thrust::malloc.

Parameters
systemThe Thrust system with which the storage is associated.
ptrA pointer previously returned by thrust::malloc. If ptr is null, free does nothing.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
Precondition
ptr shall have been returned by a previous call to thrust::malloc(system, n) or thrust::malloc<T>(system, n) for some type T.

The following code snippet demonstrates how to use free to deallocate a range of memory previously allocated with thrust::malloc.

#include <thrust/memory.h>
...
// allocate storage for 100 ints with thrust::malloc
const int N = 100;
thrust::device_system_tag device_sys;
thrust::pointer<int,thrust::device_system_tag> ptr = thrust::malloc<int>(device_sys, N);
// mainpulate memory
...
// deallocate ptr with thrust::free
thrust::free(device_sys, ptr);
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.

Parameters
systemThe Thrust system with which the storage is associated.
pA pointer previously returned by thrust::get_temporary_buffer. If ptr is null, return_temporary_buffer does nothing.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
Precondition
p shall have been previously allocated by thrust::get_temporary_buffer.

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;
typedef thrust::pair<
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 Also
free
get_temporary_buffer