how to free device_vector<int>

两盒软妹~` 提交于 2019-12-06 01:14:34

device_vector deallocates the storage associated when it goes out of scope, just like any standard c++ container.

If you'd like to deallocate any Thrust vector's storage manually during its lifetime, you can do so using the following recipe:

// empty the vector
vec.clear();

// deallocate any capacity which may currently be associated with vec
vec.shrink_to_fit();

The swap trick mentioned in Roger Dahl's answer should also work.

Roger Dahl

clear() sets the size of the vector to 0, but may not release the associated memory. The standard way to release the memory with STL is to swap the vector with an empty vector. It should work for Thrust as well.

v.clear();
device_vector<T>().swap(v);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!