thrust::uninitialized_fill_n
Defined in thrust/uninitialized_fill.h
-
template<typename ForwardIterator, typename Size, typename T>
ForwardIterator thrust::uninitialized_fill_n(ForwardIterator first, Size n, const T &x) In
thrust
, the functionthrust::device_new
allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. If each iterator in the range[first, first+n)
points to uninitialized memory, thenuninitialized_fill
creates copies ofx
in that range. That is, for each iteratori
in the range[first, first+n)
,uninitialized_fill
creates a copy ofx
in the location pointed toi
by callingForwardIterator's
value_type's
copy constructor.The following code snippet demonstrates how to use
uninitialized_fill
to initialize a range of uninitialized memory.#include <thrust/uninitialized_fill.h> #include <thrust/device_malloc.h> struct Int { __host__ __device__ Int(int x) : val(x) {} int val; }; ... const int N = 137; Int val(46); thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N); thrust::uninitialized_fill_n(array, N, val); // Int x = array[i]; // x.val == 46 for all 0 <= i < N
See also
uninitialized_fill
See also
fill
See also
uninitialized_copy_n
See also
device_new
See also
device_malloc
- Parameters
first – The first element of the range of interest.
n – The size of the range of interest.
x – The value to use as the exemplar of the copy constructor.
- Template Parameters
ForwardIterator – is a model of Forward Iterator,
ForwardIterator
is mutable, andForwardIterator's
value_type
has a constructor that takes a single argument of typeT
.- Returns
first+n