[Scummvm-cvs-logs] SF.net SVN: scummvm:[54243] scummvm/trunk
Bluddy at users.sourceforge.net
Bluddy at users.sourceforge.net
Mon Nov 15 14:37:07 CET 2010
Revision: 54243
http://scummvm.svn.sourceforge.net/scummvm/?rev=54243&view=rev
Author: Bluddy
Date: 2010-11-15 13:37:06 +0000 (Mon, 15 Nov 2010)
Log Message:
-----------
CONFIGMAN: added defragmentation methods for one-plugin-at-a-time
One-plugin-at-a-time can have fragmentation caused by the ConfigManager if a game changes any configuration value. By reallocating and copying over the ConfigManager, we avoid this problem.
Modified Paths:
--------------
scummvm/trunk/base/main.cpp
scummvm/trunk/common/config-manager.cpp
scummvm/trunk/common/config-manager.h
scummvm/trunk/common/singleton.h
Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp 2010-11-15 13:36:34 UTC (rev 54242)
+++ scummvm/trunk/base/main.cpp 2010-11-15 13:37:06 UTC (rev 54243)
@@ -408,6 +408,8 @@
#if defined(ONE_PLUGIN_AT_A_TIME) && defined(DYNAMIC_MODULES)
// do our best to prevent fragmentation by unloading as soon as we can
PluginManager::instance().unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
+ // reallocate the config manager to get rid of any fragmentation
+ ConfMan.defragment();
#endif
// Did an error occur ?
Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp 2010-11-15 13:36:34 UTC (rev 54242)
+++ scummvm/trunk/common/config-manager.cpp 2010-11-15 13:37:06 UTC (rev 54243)
@@ -53,7 +53,28 @@
ConfigManager::ConfigManager() : _activeDomain(0) {
}
+void ConfigManager::defragment() {
+ ConfigManager *newInstance = new ConfigManager();
+ newInstance->copyFrom(*_singleton);
+ delete _singleton;
+ _singleton = newInstance;
+}
+void ConfigManager::copyFrom(ConfigManager &source) {
+ _transientDomain = source._transientDomain;
+ _gameDomains = source._gameDomains;
+ _appDomain = source._appDomain;
+ _defaultsDomain = source._defaultsDomain;
+#ifdef ENABLE_KEYMAPPER
+ _keymapperDomain = source._keymapperDomain;
+#endif
+ _domainSaveOrder = source._domainSaveOrder;
+ _activeDomainName = source._activeDomainName;
+ _activeDomain = &_gameDomains[_activeDomainName];
+ _filename = source._filename;
+}
+
+
void ConfigManager::loadDefaultConfigFile() {
// Open the default config file
assert(g_system);
@@ -596,7 +617,6 @@
#pragma mark -
-
void ConfigManager::Domain::setDomainComment(const String &comment) {
_domainComment = comment;
}
Modified: scummvm/trunk/common/config-manager.h
===================================================================
--- scummvm/trunk/common/config-manager.h 2010-11-15 13:36:34 UTC (rev 54242)
+++ scummvm/trunk/common/config-manager.h 2010-11-15 13:37:06 UTC (rev 54243)
@@ -141,6 +141,9 @@
const DomainMap & getGameDomains() const { return _gameDomains; }
DomainMap & getGameDomains() { return _gameDomains; }
+ static void defragment(); // move in memory to reduce fragmentation
+ void copyFrom(ConfigManager &source);
+
private:
friend class Singleton<SingletonBaseType>;
ConfigManager();
Modified: scummvm/trunk/common/singleton.h
===================================================================
--- scummvm/trunk/common/singleton.h 2010-11-15 13:36:34 UTC (rev 54242)
+++ scummvm/trunk/common/singleton.h 2010-11-15 13:37:06 UTC (rev 54243)
@@ -39,8 +39,6 @@
Singleton<T>(const Singleton<T> &);
Singleton<T> &operator=(const Singleton<T> &);
- static T *_singleton;
-
/**
* The default object factory used by the template class Singleton.
* By specialising this template function, one can make a singleton use a
@@ -89,6 +87,8 @@
#endif
typedef T SingletonBaseType;
+
+ static T *_singleton;
};
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list