Thrust: transform_reduce : cudaMalloc in unary_op.operator <p>In my <code>unary_op.operator</code>, I need to create a temporary array.<br> I guess <code>cudaMalloc</code> is the way to go.<br> But, is it performance efficient or is there a better design?</p> <pre><code>struct my_unary_op { __host__ __device__ int operator()(const int&amp; index) const { int* array; cudaMalloc((void**)&amp;array, 10*sizeof(int)); for(int i = 0; i &lt; 10; i++) array[i] = index; int sum=0; for(int i=0; i &lt; 10 ; i++) sum += array[i]; return sum; }; }; int main() { thrust::counting_iterator&lt;int&gt; first(0); thrust::counting_iterator&lt;int&gt; last = first+100; my_unary_op unary_op = my_unary_op(); thrust::plus&lt;int&gt; binary_op; int init = 0; int sum = thrust::transform_reduce(first, last, unary_op, init, binary_op); return 0; }; </code></pre>