joeGrammar
Programmer
Check out this piece of code, This is producing memory faults upon the end of my program
void DeleteAllElements()
{
STD_NAMESPACE for_each(vector<T*>::begin(), vector<T*>::end(),
---> delete_function() );
}
This is the delete_function()
bool operator() (T * const & x) const
{ delete(x);
return true;
}
As you can see there is no checking whether the "x" is allocated dynamically or not, it just goes ahead and deletes it, now 90% of the time it is, but its those few times where its trying to delete something that is not and it crashes.
MY QUESTION:
Is there a way to test if something is dynamically allocated before you delete it?
void DeleteAllElements()
{
STD_NAMESPACE for_each(vector<T*>::begin(), vector<T*>::end(),
---> delete_function() );
}
This is the delete_function()
bool operator() (T * const & x) const
{ delete(x);
return true;
}
As you can see there is no checking whether the "x" is allocated dynamically or not, it just goes ahead and deletes it, now 90% of the time it is, but its those few times where its trying to delete something that is not and it crashes.
MY QUESTION:
Is there a way to test if something is dynamically allocated before you delete it?