aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorYotam Barnoy2010-11-15 13:37:06 +0000
committerYotam Barnoy2010-11-15 13:37:06 +0000
commitfdc2a2cd81ca3547f72a21a12c23ee56cf50faa4 (patch)
tree9491240ce9b84a0ea2842f0e1cd87a9f5060dd41 /common
parent457127d2a6aba99a33b3d1212f1406a8c40dc29e (diff)
downloadscummvm-rg350-fdc2a2cd81ca3547f72a21a12c23ee56cf50faa4.tar.gz
scummvm-rg350-fdc2a2cd81ca3547f72a21a12c23ee56cf50faa4.tar.bz2
scummvm-rg350-fdc2a2cd81ca3547f72a21a12c23ee56cf50faa4.zip
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. svn-id: r54243
Diffstat (limited to 'common')
-rw-r--r--common/config-manager.cpp22
-rw-r--r--common/config-manager.h3
-rw-r--r--common/singleton.h4
3 files changed, 26 insertions, 3 deletions
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index ec9fcaee6a..67cb74d9eb 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -53,6 +53,27 @@ const char *ConfigManager::kKeymapperDomain = "keymapper";
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
@@ -596,7 +617,6 @@ bool ConfigManager::hasGameDomain(const String &domName) const {
#pragma mark -
-
void ConfigManager::Domain::setDomainComment(const String &comment) {
_domainComment = comment;
}
diff --git a/common/config-manager.h b/common/config-manager.h
index 350b88b531..1c4eb1c2d2 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -141,6 +141,9 @@ public:
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();
diff --git a/common/singleton.h b/common/singleton.h
index 2f721a65f7..e17e401f8b 100644
--- a/common/singleton.h
+++ b/common/singleton.h
@@ -39,8 +39,6 @@ private:
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 @@ protected:
#endif
typedef T SingletonBaseType;
+
+ static T *_singleton;
};
/**