From: Christian P. <cp...@se...> - 2005-01-22 12:00:11
|
Am Donnerstag 20 Januar 2005 18:45 schrieb stephan beal: > A potential solution came to mind today: > > When Factory::create(classname) is called, we count how many times any > given classname is passed. In a garbage collector thread we iterate the > factory maps every now and then and remove any factories which have 0 > hits. For this to work we have to add reference-counting to the Factories, which implies that we also need to track object destruction, and this is where it gets tricky. > The implementation for the actual tracking would be fairly trivial: one > more map added to Factory, which gets modified during create(), plus a > cleanup function: as i said, it's not that trivial. We could add a wrapper template which does the reference counting for class-types created by the factories. > The GC thread would then call > Factory<T>::instance().cleanUnusedFactories() every X seconds (5+ > minutes is probably reasonable, or after every X factory registrations > we check for unused facs). i propose to make hitsMap() internal so that > we can achieve safe locking more easily. If hitsMap() is public we > don't need cleanXXX(), as any 3rd-party code could directly manipulate > the factory map. While this isn't a problem in and of itself, it might > become problematic in a multi-threaded environment. Thus the cleanXXX() > member, to simplify any potential locking. I don't like the idea of having an implicit GC thread. > More complex variants might track how long ago a given factory was used, > or how often, or use a LRU algo with some built-in limit of factories > to hold on to. But wee also need some "plugin filesystem registry" which tells the P plugin loader which shared objects must be loaded for a particular class type that should be constructed. We actually have two different problems: 1. Plugin registry (only load plugin-lib's that are really needed) 2. Factory reference counting (cleanup of unused factories) Greetings, Christian |