thrust::malloc
Defined in thrust/memory.h
-
template<typename T, typename DerivedPolicy>
pointer<T, DerivedPolicy> thrust::malloc(const thrust::detail::execution_policy_base<DerivedPolicy> &system, std::size_t n) This version of
malloc
allocates typed uninitialized storage associated with a given system.The following code snippet demonstrates how to use
malloc
to 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::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); // manipulate memory ... // deallocate ptr with thrust::free thrust::free(device_sys, ptr);
See also
free
See also
device_malloc
- Parameters
system – The Thrust system with which to associate the storage.
n – The number of elements of type
T
which the storage should accommodate.
- Template Parameters
DerivedPolicy – The name of the derived execution policy.
- Returns
If allocation succeeds, a pointer to an allocation large enough to accommodate
n
elements of typeT
; a null pointer otherwise. The pointer must be deallocated withthrust::free
.- Pre
DerivedPolicy
must be publicly derived fromthrust::execution_policy<DerivedPolicy>
.