After I performed some operations on the vector of structs, I need to free the memory. I suppose clear() will not be sufficient, but I'm not sure how to perform individual delete.
1 2 3 4 5 6 7 8 9 10 11
typedef std::vector<VertexRAM> VecVertexRAM; // definition of a vector of structs
template <typename type>
void freeFromMemory(std::vector<type>& myVec) {
typename std::vector<type>::iterator myIter=myVec.begin();
while(myIter!=myVec.end()) {
delete(*myIter);
++myIter;
}
myVec.clear();
}
This outputs the following error:
Code:
error: type ‘struct VertexRAM’ argument given to ‘delete’, expected pointer
Are you running into memory problems? If so I suppose you could ensure that the memory would be freed by using a std::vector pointer and allocating manually. Then pass a reference to the pointer to your function.
Unless the elements of your container are themselves pointers, you don't need to do any freeing. For instance, your code would work on this container, which would need you to do freeing: