简体   繁体   English

我需要释放推力返回的device_ptr吗?

[英]Do I need to free device_ptr returned by thrust?

I have a function to get the minimum value of an array and it's executed within a loop. 我有一个函数来获取数组的最小值,它在循环内执行。

thrust::device_ptr<float> min_ptr = thrust::min_element(populationFitness, populationFitness + POPULATION);

Do I have to free the returned device_ptr? 我必须释放返回的device_ptr吗? I tried with thrust::device_free(min_ptr) but an exception is thrown. 我尝试了thrust::device_free(min_ptr)但引发了异常。

thrust::min_element returns an iterator. 推力:: min_element返回一个迭代器。 You should not free it directly. 您不应该直接释放它。

I dont think you need to free the memory returned by the thrust::min_element 我不认为您需要释放推力:: min_element返回的内存

Looking at the example code given at http://docs.thrust.googlecode.com/hg/group__extrema.html 查看http://docs.thrust.googlecode.com/hg/group__extrema.html上给出的示例代码

#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::max_element(data, data + 6);

Seems that it returns an pointer to the array element and you need not delete it . 似乎它返回了一个指向数组元素的指针,您无需删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM