I've just learned how to use vectors.
I'm thinking about, what is the best way to create a vector, IF you do not know its initial size. Here are some of my options.
1.)
This is the simplest I think, but is there any memory issue about this technique?
vector<myObject> myVector;
int size = 5;
myVector = vector<myObject>(size);
2.) Just like number 1 , but using pointer.
vector<myObject>* myVector;
int size = 5;
myVector = &(vector<myObject>(size));
3.)
vector <myObject> myVector;
int size = 5;
for (int i = 0; i < size ; i++) {
myVector.push_back( myObject() );
}
I would like to know your comments about these 3 ways, their advantages and disadvantages in terms of memory I think, or performance. Thank you very much!!!