◆ malloc() [1/2]

template<typename DerivedPolicy >
__host__ __device__ pointer<void,DerivedPolicy> thrust::malloc ( const thrust::detail::execution_policy_base< DerivedPolicy > &  system,
std::size_t  n 

This version of malloc allocates untyped uninitialized storage associated with a given system.

systemThe Thrust system with which to associate the storage.
nThe number of bytes of storage to allocate.
If allocation succeeds, a pointer to the allocated storage; a null pointer otherwise. The pointer must be deallocated with thrust::free.
Template Parameters
DerivedPolicyThe name of the derived execution policy.
DerivedPolicy must be publically derived from thrust::execution_policy<DerivedPolicy>.

The following code snippet demonstrates how to use malloc to allocate a range of memory associated with Thrust's device system.

#include <thrust/memory.h>
// allocate some memory with thrust::malloc
const int N = 100;
thrust::device_system_tag device_sys;
thrust::pointer<void,thrust::device_space_tag> void_ptr = thrust::malloc(device_sys, N);
// manipulate memory
// deallocate void_ptr with thrust::free
thrust::free(device_sys, void_ptr);
See also