I have a std::list of classes and want to remove entries that are marked for delete. I am using std::remove_if and erase.
class MyClass
{
bool isDone(MyData& myData)
{
return myData.isDone();
}
void removeIfDone(std::list<MyData>& myList)
{
std::list<MyData>::iterator it =
remove_if(myList.begin(), myList.end(),
boost::bind(&MyClass::isDone, this, _1));
myList.erase(it, myList.end());
}
};
I am running on a small processor for which memory allocation and deallocation is very expensive. This remove is calling new and delete thousands of times in my application.
I have previously used boost::ref
when passing a non-trivial variable as a bind parameter but in this case I think it is probably the creation and destruction of the functor itself or the copying of it which is causing the problem.
I would like to do something like
boost::bind(&MyClass::isDone, boost::ref(this), boost::ref(_1));
I can't find documentation on what is being created and destroyed. So my simple question is how do I make this more efficient?