Before I start, I have already looked at these questions:
Memory consumption of a pointer to vector of pointers
Pointer to vector vs vector of pointers vs pointer to vector of pointers
And they both do not answer my question.
I am working on a project where it involves millions of instances to work with.
The data structure I am using is a bit complicated to look at for the first time, the structure itself isn't really of any importance for this question.
Now, if I had the following:
vector<object*> *myVector;
Everything goes to the heap.
However, what happens if I used this:
vector<object*> myVector;
Does the vector itself get stored on the stack? And its contents are then stored on the heap? For example, if the vector had 10 million instances, would I have 10 million references on the stack for 10 million objects on the heap? Or am I missing something?
Moreover, if I used this:
vector<object> *myVector;
Where do the contents of the vector go? Does everything go on the heap? If yes, then does it work recursively? For example:
vector<vector<vector<int>>> *myVector;
Are all the inner vectors then stored on the heap? If yes, then it should be enough deleting myVector
in the destructor, without worrying on anything else?
Anyway, I am assuming all the answers that apply to vector
would also apply to unordered_map
. Please tell me if I am wrong.
Thanks in advance.