我需要释放由推力返回的device_ptr吗?
Do I need to free device_ptr returned by thrust?
我有一个函数来获取数组的最小值,它在循环中执行。
thrust::device_ptr<float> min_ptr = thrust::min_element(populationFitness, populationFitness + POPULATION);
我必须释放返回的device_ptr吗?我尝试使用thrust::device_free(min_ptr)
,但抛出异常。
thrust::min_element返回一个迭代器。你不应该直接释放它
我认为你不需要释放由thrust::min_element
返回的内存查看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);
似乎它返回一个指向数组元素的指针,你不需要删除它。
相关文章:
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- 引用 std::shared:ptr 以避免引用计数
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 尝试打印出 *ptr++ 的值,以了解它是如何工作的
- 如何控制共享 ptr 引用计数?
- 将 aws-iot-device-sdk-cpp-v2 与 CMake 结合使用
- C++中的指针否定 (!ptr == NULL)
- 从const ptr*转换为ptr*时出现问题
- 这是MSVC 2013中具有共享PTR的单例的正确实现吗?
- 对唯一 ptr 无效读取的引用向量
- C++ 类型转换基础 PTR 到派生 PTR 保存在引用类中
- 加载安全区图像"A device attached to the system is not functioning"