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

Template Parameters

DerivedPolicy – The name of the derived execution policy.

Returns

If allocation succeeds, a pointer to an allocation large enough to accomodate n elements of type T; a null pointer otherwise. The pointer must be deallocated with thrust::free.

Pre

DerivedPolicy must be publically derived from thrust::execution_policy<DerivedPolicy>.