R
Rakesh Sinha
This is about the vector template defined in standard C++ .
Suppose I want to create a *huge* vector , as follows.
void f1() {
vector < int > data(1024); //may be not very huge, but for
//demonstration purposes
//Process 'data'
//'data' goes out of scope
//and storage reclaimed automatically
}
void f2() {
vector < int > * p = new vector <int>f1(1024); //
//Process 'p'
delete p; //Explicitly reclaim storage.
}
My question is, given that we want to create a huge vector , which one
among the two is better ?
* If this had been not been a container, then I would
have chosen 'f1()' because it does not involve pointers.
* If this had been not been a container but a *big object*,
may be 'f2()' might be better.
* Given that vector manages dynamic memory allocation internally, are
there any important differences between 'f1()' and 'f2()' at all ?
I am little bit confused here. Please let me know your comments.
Suppose I want to create a *huge* vector , as follows.
void f1() {
vector < int > data(1024); //may be not very huge, but for
//demonstration purposes
//Process 'data'
//'data' goes out of scope
//and storage reclaimed automatically
}
void f2() {
vector < int > * p = new vector <int>f1(1024); //
//Process 'p'
delete p; //Explicitly reclaim storage.
}
My question is, given that we want to create a huge vector , which one
among the two is better ?
* If this had been not been a container, then I would
have chosen 'f1()' because it does not involve pointers.
* If this had been not been a container but a *big object*,
may be 'f2()' might be better.
* Given that vector manages dynamic memory allocation internally, are
there any important differences between 'f1()' and 'f2()' at all ?
I am little bit confused here. Please let me know your comments.