thrust::get_temporary_buffer#
-
template<typename T, typename DerivedPolicy>
thrust::pair<thrust::pointer<T, DerivedPolicy>, typename thrust::pointer<T, DerivedPolicy>::difference_type> thrust::get_temporary_buffer( - const thrust::detail::execution_policy_base<DerivedPolicy> &system,
- typename thrust::pointer<T, DerivedPolicy>::difference_type n,
get_temporary_bufferreturns a pointer to storage associated with a given Thrust system sufficient to store up tonobjects of typeT. If not enough storage is available to accommodatenobjects, an implementation may return a smaller buffer. The number of objects the returned buffer can accommodate is also returned.Thrust uses
get_temporary_bufferinternally when allocating temporary storage required by algorithm implementations.The storage allocated with
get_temporary_buffermust be returned to the system withreturn_temporary_buffer.The following code snippet demonstrates how to use
get_temporary_bufferto allocate a range of memory to accommodate integers associated with Thrust’s device system.#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
See also
- Parameters:
system – The Thrust system with which to associate the storage.
n – The requested number of objects of type
Tthe storage should accommodate.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
- Returns:
A pair
psuch thatp.firstis a pointer to the allocated storage andp.secondis the number of contiguous objects of typeTthat the storage can accommodate. If no storage can be allocated,p.firstif no storage can be obtained. The storage must be returned to the system usingreturn_temporary_buffer.- Pre:
DerivedPolicymust be publicly derived fromthrust::execution_policy<DerivedPolicy>.