Z
zl2k
hi, all
I need to use gsl_vector pointer with std::vector but not sure how to
free the memory when I don't need it. Here is a piece of the code.
===================
std::vector<gsl_vector * > v;
gsl_vector * a = gsl_vector_alloc(3);
gsLvector_set(a, 0, 7);
v.push_back(a);
gsl_vector_free(a); // problem! after a is free, the v[0] is null
std::cout<<gsl_vector_get(v[0], 0)<<std::endl;
===================
How can I free the memory when I don't need them? If I say
v.clear();
will the memory allocated by the gsl_vector still hold by the
unreachable vectors?
Or should I do
for (int i = 0; i < v.size(); i++){
gsl_vector_free(v);
}
v.clear();
to free the memory? But iterating on each elements of the vector is
tedious if the std::vector is long. Is there any easy way to deal with
the problem? Thanks for comments.
zl2k
I need to use gsl_vector pointer with std::vector but not sure how to
free the memory when I don't need it. Here is a piece of the code.
===================
std::vector<gsl_vector * > v;
gsl_vector * a = gsl_vector_alloc(3);
gsLvector_set(a, 0, 7);
v.push_back(a);
gsl_vector_free(a); // problem! after a is free, the v[0] is null
std::cout<<gsl_vector_get(v[0], 0)<<std::endl;
===================
How can I free the memory when I don't need them? If I say
v.clear();
will the memory allocated by the gsl_vector still hold by the
unreachable vectors?
Or should I do
for (int i = 0; i < v.size(); i++){
gsl_vector_free(v);
}
v.clear();
to free the memory? But iterating on each elements of the vector is
tedious if the std::vector is long. Is there any easy way to deal with
the problem? Thanks for comments.
zl2k