I have a function uint32_t* getDataP(uint idx);,
I have no access to the code of the function.
I need to implement a code ,which calls the function with different idx arguments
and saves the results in the vector.
What is the better way to save it in the vector<uint32_t> or vector<uint32_t*>?
If I decide to save it as vector<uint32_t*> savedData,is the following implementation is OK?:
for (uint i = 0; i < 10;++ i) {
dataP = getDataP(i);
savedData.push_back(dataP);
}
Need I perform a deep copy of dataP ?or the above is sufficient?
If you save only the pointer, who will be responsible for cleaning up, you or the library ? And is the memory pointed to going to be available for the entire lifetime of your code ?
I would say go with vector<uint32_t>, as it’s safer, but I don’t really know what your application is doing.
You loop would then become: