thrust::device_malloc

Defined in thrust/device_malloc.h

template<typename T = void>
device_ptr<T> thrust::device_malloc(const std::size_t n)

Allocates sequential device storage for new objects of a given type, or raw bytes if the type is void.

The following code snippet demonstrates how to use device_malloc to allocate a range of device memory.

#include <thrust/device_malloc.h>
#include <thrust/device_free.h>
...
// allocate some integers with device_malloc
const int N = 100;
thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
thrust::device_ptr<void> raw_byte_array = thrust::device_malloc(N);

// manipulate integers and bytes
...

// deallocate with device_free
thrust::device_free(raw_byte_array);
thrust::device_free(int_array);

See also

device_ptr

See also

device_free

Parameters

n – The number of objects of type T, or bytes, to allocate sequentially in device memory.

Returns

A device_ptr to the newly allocated memory.