ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/BlockSnapshotManager.cpp
(Generate patch)

Comparing trunk/src/brains/BlockSnapshotManager.cpp (file contents):
Revision 1966 by gezelter, Fri Jan 24 14:17:42 2014 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 53 | Line 53 | namespace OpenMD {
53                                               int storageLayout,
54                                               long long int memSize,
55                                               int blockCapacity)
56 <    : SnapshotManager(storageLayout), info_(info), memSize_(memSize),
57 <      blockCapacity_(blockCapacity), activeBlocks_(blockCapacity_, -1),
56 >    : SnapshotManager(storageLayout), info_(info),
57 >      blockCapacity_(blockCapacity), memSize_(memSize),
58 >      activeBlocks_(blockCapacity_, -1),
59        activeRefCount_(blockCapacity_, 0) {
60  
61        nAtoms_ = info->getNGlobalAtoms();
# Line 163 | Line 164 | namespace OpenMD {
164  
165    bool BlockSnapshotManager::loadBlock(int block) {
166      std::vector<int>::iterator i = findActiveBlock(block);
167 <    bool loadSuccess;
167 >    bool loadSuccess(false);
168      if (i != activeBlocks_.end()) {
169 <      //if block is already in memory, just increast the reference count
169 >      // If the block is already in memory, just increase the
170 >      // reference count:
171        ++activeRefCount_[i - activeBlocks_.begin()];
172        loadSuccess = true;
173      } else if (getNActiveBlocks() < blockCapacity_){
174 <      //if number of active blocks is less than the block capacity, just load it
174 >      // If the number of active blocks is less than the block
175 >      // capacity, just load the block:
176        internalLoad(block);
177        loadSuccess = true;
178      } else if ( hasZeroRefBlock() ) {
179 <      //if already reach the block capacity, need to unload a block with 0 reference
179 >      // If we have already reached the block capacity, we need to
180 >      // unload a block with 0 references:
181        int zeroRefBlock = getFirstZeroRefBlock();
182        assert(zeroRefBlock != -1);
183        internalUnload(zeroRefBlock);
184        internalLoad(block);
185      } else {
186 <      //reach the capacity and all blocks in memory are not zero reference
186 >      // We have reached capacity and all blocks in memory are have
187 >      // non-zero references:
188        loadSuccess = false;
189 <    }
185 <    
189 >    }    
190      return loadSuccess;
191    }
192  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines