1
我有下面的代碼保存點雲在我的GPU緩存:的OpenCL/C++ - 返回一個CL ::緩衝區對象
cl::Buffer writePointCloudToGPU(pcl::PointCloud<pcl::PointXYZ>& pointCloud){
cl_int err;
cl::Buffer bufferCloud(getContext(), CL_MEM_READ_WRITE, sizeof(pcl::PointXYZ) * pointCloud.size(), NULL, &err);
getQueue().enqueueWriteBuffer(bufferCloud, CL_TRUE, 0, sizeof(pcl::PointXYZ) * pointCloud.size(), const_cast<float*> (&pointCloud.points[0].x), NULL);
return bufferCloud;
}
這是否會導致內存泄漏問題,當我返回CL ::緩衝?一旦我返回bufferCloud對象,它的程序何時釋放它呢?
對於1.2版,沒有在析構函數,其中,被稱爲釋放()時,例如超出範圍(當您返回後拷貝構造函數的工作就被破壞了,當你把它分配給一個變量,又稱爲析構函數在複製構造函數調用之後,當超出範圍時,調用它的析構函數)。對於2.0+版本,裏面有智能指針,所以更好的用法可以在那裏。也許複製elision在裏面工作。 –