void ConfigManager::loadDefaultConfigFile() { char configFile[MAXPATHLEN]; #if defined(UNIX) #if defined (IPOD) strcpy(configFile, DEFAULT_CONFIG_FILE); #else const char *home = getenv("HOME"); if (home != NULL && strlen(home) < MAXPATHLEN) snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); else strcpy(configFile, DEFAULT_CONFIG_FILE); #endif #else #if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) GetWindowsDirectory(configFile, MAXPATHLEN); strcat(configFile, "\\" DEFAULT_CONFIG_FILE); #elif defined(PALMOS_MODE) strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); #elif defined(__PLAYSTATION2__) ((OSystem_PS2*)g_system)->makeConfigPath(configFile); #elif defined(__PSP__) strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); #elif defined (__SYMBIAN32__) strcpy(configFile, Symbian::GetExecutablePath()); strcat(configFile, DEFAULT_CONFIG_FILE); #else strcpy(configFile, DEFAULT_CONFIG_FILE); #endif #endif loadConfigFile(configFile); flushToDisk(); }
ChainArray::~ChainArray() { for (uint i = 0; i < nstacks_*nchains_; i++) { if (cache_[i].size() > 0) flushToDisk(i); } }
bool ChainArray::append(uint id, const Eigen::VectorXd& sample, double energy) { State newState = {sample, energy, sigma_[id], beta_[id], false, SwapType::NoAttempt}; State last = lastState(id); bool accepted = acceptProposal(newState, last, beta_[id]); if (accepted) cache_[id].push_back(newState); else cache_[id].push_back(last); cache_[id].back().accepted = accepted; cache_[id].back().swapType = SwapType::NoAttempt; if (cache_[id].size() == cacheLength_) flushToDisk(id); return accepted; }
void ConfigManager::loadDefaultConfigFile() { // Open the default config file assert(g_system); SeekableReadStream *stream = g_system->createConfigReadStream(); _filename.clear(); // clear the filename to indicate that we are using the default config file // ... load it, if available ... if (stream) { loadFromStream(*stream); // ... and close it again. delete stream; } else { // No config file -> create new one! debug("Default configuration file missing, creating a new one"); flushToDisk(); } }
// The following is not true at the moment... // This method takes a snapshot of the system's current state and stores // it in memory. If no memory is available or a maximum number of // snapshots has been taken, all snapshots so far are saved to disk The // first snapshot taken (and with no other previous snapshots in a file) // has index 1. void SnapShotManager::takeSnapShot() throw(File::CannotWrite) { if (system_ptr_ == 0) return; // One more snapshot. Add it to the current list of snapshots // The way we do it here should be faster, than filling the // SnapShot with data first and pushing it into the vector afterwards. snapshot_buffer_.push_back(SnapShot()); SnapShot& snapshot = snapshot_buffer_[snapshot_buffer_.size() - 1]; // store all current positions, forces, velocities in the // snapshot object snapshot.takeSnapShot(*system_ptr_); // store the potential energies if (force_field_ptr_ != 0) { snapshot.setPotentialEnergy(force_field_ptr_->getEnergy()); } // store the kinetic energy of all selected atoms in the system // the current value must be calculated as it is not provided by // the force field snapshot.setKineticEnergy(calculateKineticEnergy_()); buffer_counter_++; // We could! use pushback() and size() to determine when to flush the // buffers, but this is faster. if (buffer_counter_ >= flush_to_disk_frequency_) { // write all snapshots to disk in order to prevent memory overflow flushToDisk(); } } // end of SnapShotManager::takeSnapShot()
/* decompress a file in memory */ void decompress_file(char *prefix, int file, int offset) { /* */ z_stream zptr; int state, fmax = -1; int ret, firstpass, bitmaplg; FILE *fi; PARAMS currentparams; /* open another chunk */ char filename[256]; /* clear memory buffer */ memset(all, 0, 1024*88064); state = Z_SYNC_FLUSH; firstpass = 1; bitmaplg = 0; zptr.zalloc = NULL; zptr.zfree = NULL; sprintf(filename, "%s%03d", prefix, file); fi = fopen (filename, "r"); if (fi == NULL) { printf ("Cannot open input file %s\n", filename); } DEBUG(printf("New file opened: %s\n", filename)); zptr.avail_in = fread (IN, 1, INSIZE, fi); currentparams.fo = 0; currentparams.offset = 0; currentparams.bitindex = 0; zptr.next_in = (char *) IN; zptr.next_out = (char *) BUFFER; // was dbuf.data; zptr.avail_out = 24064; inflateInit (&zptr); do { ret = inflate (&zptr, state); /* output buffer full */ if ((ret == Z_OK) && (zptr.avail_out == 0)) { if (firstpass) { DEBUG (printf ("Params : *%s\n", BUFFER)); if (strstr (BUFFER, "BLOCKS=")) { int i = 0; if (sscanf (strstr (BUFFER, "BLOCKS=") + 7, "%d", &i) == 1) { fmax = i; } } if (strstr (BUFFER, "ALLOCTABLELG=")) sscanf (strstr (BUFFER, "ALLOCTABLELG=") + 13, "%d", &bitmaplg); memcpy (Bitmap, BUFFER + 2048, 24064 - 2048); currentparams.bitindex = 0; firstpass = 0; } else { flushToDisk (BUFFER, Bitmap, ¤tparams, 24064); } zptr.next_out = (char *) BUFFER; zptr.avail_out = 24064; } /* no more data in */ if ((ret == Z_OK) && (zptr.avail_in == 0)) { zptr.avail_in = fread (IN, 1, INSIZE, fi); zptr.next_in = (char *) IN; } } while (ret == Z_OK); /* end of file */ if (ret == Z_STREAM_END) { { if (firstpass) { /* only one block */ DEBUG (printf ("Params : *%s*\n", BUFFER)); if (strstr (BUFFER, "BLOCKS=")) { int i = 0; if (sscanf (strstr (BUFFER, "BLOCKS=") + 7, "%d", &i) == 1) { fmax = i; } } if (strstr (BUFFER, "ALLOCTABLELG=")) sscanf (strstr (BUFFER, "ALLOCTABLELG=") + 13, "%d", &bitmaplg); memcpy (Bitmap, BUFFER + 2048, 24064 - 2048); zptr.next_out = (char *) BUFFER; zptr.avail_out = 24064; } } flushToDisk (BUFFER, Bitmap, ¤tparams, 24064 - zptr.avail_out); zptr.next_out = (char *) BUFFER; zptr.avail_out = 24064; } ret = inflate (&zptr, Z_FINISH); inflateEnd (&zptr); /* ERROR */ if (ret < 0) { printf ("Returned : %d\t", ret); printf ("(AvailIn : %d / ", zptr.avail_in); printf ("AvailOut: %d)\n", zptr.avail_out); printf ("(TotalIn : %ld / ", zptr.total_in); printf ("TotalOut: %ld)\n", zptr.total_out); } if (bitmaplg) { if (bitmaplg * 8 > currentparams.bitindex) { currentparams.offset += 512 * (bitmaplg * 8 - currentparams.bitindex); if (currentparams.fo) { // why fill ? //fill(currentparams.fo,512*(bitmaplg*8-currentparams.bitindex),SEEK_CUR); } } } fclose(fi); }