As the ml tends to strip even patches, you can find a mirror of the patch here: http://kurosu.free.fr/wormux/singleton.diff
Kurosu a écrit : > For 1), I think there should maybe be a factory or whatever, holding a > list of all the created instances, and providing some method to destroy > all instances. I'm hitting here my limited practice of pattern designs > (and I'm still not ready to be publicly shamed on comp.lang.c++ :) Like Julien mentioned, it seems sufficient to: - derive singleton from a base class so that we aren't bothered by the template part of the object - maintain / delegate instances of that base type globally. > For 2), I guess the simplest would be to always let the derived class > implement it if there's a real problem here. That works, even for static members. So, Game, recently modified to have GetInstance check the mode to return an object of proper type (derived from Game), does work. I think the current code essentially preserves the old behavior. It's a bit cumbersome to move construct/destructor as protected members with the base class a friend, but I don't think I'm going to give that point more thinking. There are a number of corner cases (making it not a CS perfection) though: 1) AppWormux is a singleton, yet it is not derived from Singleton (hen and egg problem mostly but I haven't looked more; it's probably trivial if calling the BaseSingleton::ReleaseSingletons method in main) 2) Threading That is a fundamentally cumbersome problem, but I was afraid that having a lock in GetInstance would impact performance (which is currently a bit too low to my liking) At least, I could change the singletons.push_back and singletons.remove calls to BaseSingleton static methods which would do proper locking around said above calls. Then only constructors would be affected, still not alleviating the problem that 2 threads may call GetInstance of the same class and its constructor being so slow that one occurs during the other. Real problem, lack of energy over this problem => delta for later 3) Real corner cases: - Mine has a strange handling pattern so I didn't bother with it, as it is probably freed with something else - Network: not yet modified Best regards, -- Kurosu
_______________________________________________ Wormux-dev mailing list Wormux-dev@gna.org https://mail.gna.org/listinfo/wormux-dev