I have an application that creates thousands of small objects (upwards of 500,000). There is an object factory that allocates these objects on the heap.
The problem that I'm running into is that when the object that holds these smaller object goes out of scope (Driver), 65% of the processing time is spent destroying these small objects.
map
, entries
, and fields
hold pointers to an abstract base class, and each base class has many child classes.
The application architecture follows this format:
class Driver {
boost::ptr_map<std::string, Class1-Base> map;
}
class Class1-Base {
boost::ptr_vector<Class2-Base> entries;
}
class Class2-Base {
boost::ptr_vector<Class3-Base> fields;
}
class Class3-Base {
unsigned long value;
}
I have tried several different methods to increase the application's performance.
I first used a data structures with normal pointers and then explicitly deleted the objects in the class's destructor.
I then tried using data structures with boost::shared_ptr<>
but I determined that reference counting caused a significant overhead and didn't provide any great benefit.
The solution I've come to now is to use boost::ptr_container
so it takes ownership of the heap objects and will automatically destroy them when the container goes out of scope. With this solution, significant time is still spent destroying objects.
Is there anything I can do to prevent all this time destroying objects?