Hello,
If I create an STL vector, is the memory assigned on the heap or the stack?
For example:
Are the contents of "my_vector" on the heap, or the stack? I haven't declared the vector using the "new" keyword, so for a normal object, it would be created on the stack. But because a vector is a STL object, does it behave differently?Code:#include <vector>
int main()
{
std::vector<int> my_vector(3);
my_vector[0] = 1;
my_vector[1] = 10;
my_vector[2] = 100;
return 0;
}
If the vector is created on the heap, then how do I free the memory? Do I follow the standard approach:
If your answer to the first part is the the vector is created on the stack, then how do I in fact create it on the heap? Do I use :Code:// Free up the space allocated to the vector
delete &my_vector;
// Or perhaps this?
delete my_vector;
Thanks for the help :)Code:std::vector<int>* my_vector = new std::vector<int>(3);

