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
This commit is contained in:
parent
457127d2a6
commit
fdc2a2cd81
4 changed files with 28 additions and 3 deletions
|
@ -408,6 +408,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
|
|||
#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 ?
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue