const VISU::ColoredPrs3dHolder::BasicInput& theInput,
float& theMemoryToClear)
{
- //cout << "VISU::ColoredPrs3dCache_i::IsPossible " << endl;
+ //if(MYDEBUG) cout << "VISU::ColoredPrs3dCache_i::IsPossible" << endl;
size_t aMemory = VISU::CheckIsPossible(theType, theInput, true);
if(aMemory > 0){
CORBA::Float aMemoryUsed = GetMemorySize();
CORBA::Float aMemoryLimit = GetLimitedMemory();
CORBA::Float aMemoryNeeded = CORBA::Float(aMemory/(1024.0*1024.0)); // convert to Mb
- //cout<<"Memory needed: "<<aMemoryNeeded<<"; used: "<<aMemoryUsed<<"; limit: "<<aMemoryLimit<<endl;
+ if(MYDEBUG) cout<<"Memory needed: "<<aMemoryNeeded<<"; used: "<<aMemoryUsed<<"; limit: "<<aMemoryLimit<<endl;
if( aMemoryUsed + aMemoryNeeded < aMemoryLimit )
return true;
theMemoryToClear = aMemoryNeeded;
- return true;
+ bool ok = ClearMemory( theMemoryToClear, NULL, true );
+ return ok;
}
}
return aMemory > 0;
const VISU::ColoredPrs3dHolder::BasicInput& theInput,
VISU::View3D_ptr theView3D)
{
- //cout << "VISU::ColoredPrs3dCache_i::UpdateLastVisitedPrs" << endl;
+ if(MYDEBUG) cout << "VISU::ColoredPrs3dCache_i::UpdateLastVisitedPrs" << endl;
TPrs3dPtr aLastVisitedPrs3d = GetLastVisitedPrs(theHolder);
TLastVisitedPrsList& aLastVisitedPrsList = GetLastVisitedPrsList(theHolder);
TPrs3dPtr aPrs3d = FindPrsByInput(aLastVisitedPrsList, theInput);
float aMemoryToClear = 0.;
if(aPrs3d.GetPointer()){
aLastVisitedPrsList.push_front(aPrs3d);
- //cout << "FindPrsByInput " << aPrs3d;
+ if(MYDEBUG) cout << "FindPrsByInput " << aPrs3d << endl;
}else if(anIsCheckPossible && IsPossible(theHolder->GetPrsType(), theInput, aMemoryToClear)){
if( aMemoryToClear > 1 / VTK_LARGE_FLOAT )
ClearMemory(aMemoryToClear, theHolder);
aPrs3d = CreatePrs(theHolder->GetPrsType(), theInput, theHolder);
- //cout << "Created " << aPrs3d;
+ if(MYDEBUG) cout << "Created " << aPrs3d << endl;
}else{
aPrs3d = aLastVisitedPrsList.back();
+ aPrs3d->SetResultObject(theInput.myResult);
+ aPrs3d->SetMeshName(theInput.myMeshName);
+ aPrs3d->SetEntity(theInput.myEntity);
+ aPrs3d->SetFieldName(theInput.myFieldName);
+ aPrs3d->SetTimeStampNumber(theInput.myTimeStampNumber);
aLastVisitedPrsList.pop_back();
aLastVisitedPrsList.push_front(aPrs3d);
- //cout << "Move only " << aPrs3d;
+ if(MYDEBUG) cout << "Move only " << aPrs3d << endl;
}
- //cout << "; " << aLastVisitedPrsList.size() << endl;
+ if(MYDEBUG) PrintCache();
- aPrs3d->SetResultObject(theInput.myResult);
- aPrs3d->SetMeshName(theInput.myMeshName);
- aPrs3d->SetEntity(theInput.myEntity);
- aPrs3d->SetFieldName(theInput.myFieldName);
- aPrs3d->SetTimeStampNumber(theInput.myTimeStampNumber);
aPrs3d->SameAs(thePrs);
aPrs3d->UpdateActors();
if(!CORBA::is_nil(theView3D)){
VISU::ColoredPrs3dCache_i
::ClearCache(float theMemory)
{
- //cout << "VISU::ColoredPrs3dCache_i::ClearCache( " << theMemory << " )" << endl;
+ //if(MYDEBUG) cout << "VISU::ColoredPrs3dCache_i::ClearCache( " << theMemory << " )" << endl;
float aCurrentMemory = GetMemorySize();
ClearMemory( aCurrentMemory - theMemory, NULL );
//----------------------------------------------------------------------------
-void
+bool
VISU::ColoredPrs3dCache_i
-::ClearMemory(float theMemory, VISU::ColoredPrs3dHolder_i* theActiveHolder)
+::ClearMemory(float theMemory, VISU::ColoredPrs3dHolder_i* theActiveHolder, bool theOnlyCheck)
{
- if(MYDEBUG) cout << "VISU::ColoredPrs3dCache_i::ClearMemory( " << theMemory << " )" << endl;
+ if(MYDEBUG)
+ {
+ cout << "VISU::ColoredPrs3dCache_i::ClearMemory( ";
+ cout << (int)theOnlyCheck;
+ cout << " , " << theMemory;
+ if( theActiveHolder )
+ cout << " , " << theActiveHolder->GetEntry().c_str();
+ cout << " )" << endl;
+ }
if( theMemory < 1 / VTK_LARGE_FLOAT )
- return;
+ return false;
if(MYDEBUG) PrintCache();
TColoredPrs3dHolderMap::iterator aHolderIter = myHolderMap.begin();
TColoredPrs3dHolderMap::iterator aHolderIterEnd = myHolderMap.end();
+ std::string anEntry;
+ if( theActiveHolder )//&& myHolderMap.size() > 1 )
+ anEntry = theActiveHolder->GetEntry();
+
int anIteration = 0;
for( ; aHolderIter != aHolderIterEnd; aHolderIter++ )
{
+ if( aHolderIter->first == anEntry )
+ continue;
TLastVisitedPrsList& aPrsList = aHolderIter->second;
anIteration = QMAX( aPrsList.size() - 1, anIteration );
}
if(MYDEBUG) cout << "Iteration - " << anIteration << endl;
- std::string anEntry;
- if( theActiveHolder )
- anEntry = theActiveHolder->GetEntry();
-
float aMemory, aGatheredMemory = 0.;
while( anIteration > 0 )
{
for( aHolderIter = myHolderMap.begin(); aHolderIter != aHolderIterEnd; aHolderIter++ )
{
- //if( aHolderIter->first == anEntry )
- //continue;
+ if( aHolderIter->first == anEntry )
+ continue;
TLastVisitedPrsList& aPrsList = aHolderIter->second;
if( anIteration < aPrsList.size() )
aGatheredMemory += aMemory;
if(MYDEBUG) cout << aMemory << " >> " << aGatheredMemory;
- aPrsList.pop_back();
+ if( !theOnlyCheck )
+ aPrsList.pop_back();
if( aGatheredMemory > theMemory )
{
if(MYDEBUG) cout << " STOP" << endl;
- goto stop;
+ if(MYDEBUG) PrintCache();
+ return true;
}
if(MYDEBUG) cout << endl;
}
}
-
anIteration--;
}
- stop:
+ // clear active holder in a last order
+ if( theActiveHolder )
+ {
+ aHolderIter = myHolderMap.find( anEntry );
+
+ TLastVisitedPrsList& aPrsList = aHolderIter->second;
+ TLastVisitedPrsList::reverse_iterator aPrsIter = aPrsList.rbegin();
+ TLastVisitedPrsList::reverse_iterator aPrsIterEnd = aPrsList.rend();
+ for(; aPrsIter != aPrsIterEnd; aPrsIter++)
+ {
+ TPrs3dPtr aPrs3d = *aPrsIter;
+ if(MYDEBUG) cout << aPrs3d.GetPointer() << " ";
+ if( !aPrs3d.GetPointer() )
+ continue;
+
+ aMemory = aPrs3d->GetMemorySize();
+ aGatheredMemory += aMemory;
+ if(MYDEBUG) cout << aMemory << " >> " << aGatheredMemory;
+
+ if( !theOnlyCheck )
+ aPrsList.pop_back();
+
+ if( aGatheredMemory > theMemory )
+ {
+ if(MYDEBUG) cout << " STOP" << endl;
+ if(MYDEBUG) PrintCache();
+ return true;
+ }
+ if(MYDEBUG) cout << endl;
+ }
+ }
+
if(MYDEBUG) PrintCache();
+ return false;
}
VISU::ColoredPrs3dCache_i
::PrintCache()
{
- cout << "VISU::ColoredPrs3dCache_i::PrintCache()" << endl;
-
+ cout << "--------------CACHE-----------------" << endl;
cout << "Cache memory - " << GetMemorySize() << " Mb" << endl;
TColoredPrs3dHolderMap::const_iterator aHolderIter = myHolderMap.begin();
TColoredPrs3dHolderMap::const_iterator aHolderIterEnd = myHolderMap.end();
TLastVisitedPrsList::const_iterator aPrsIter = aPrsList.begin();
TLastVisitedPrsList::const_iterator aPrsIterEnd = aPrsList.end();
+ cout << "--------------------------" << endl;
cout << "Holder - " << aHolderIter->first.c_str() << endl;
cout << "Size - " << aPrsList.size() << endl;
- for(aPrsIter++; aPrsIter != aPrsIterEnd; aPrsIter++)
+ for(; aPrsIter != aPrsIterEnd; aPrsIter++)
if(TPrs3dPtr aPrs3d = *aPrsIter)
- cout << aPrs3d.GetPointer() << " (" << aPrs3d->GetMemorySize() << " Mb)"<< endl;
+ {
+ cout << aPrs3d.GetPointer() << " (" << aPrs3d->GetMemorySize() << " Mb)";
+ if(aPrsIter == aPrsList.begin())
+ cout << " (device)";
+ cout << endl;
+ }
}
+ cout << "------------------------------------" << endl;
}
+
//----------------------------------------------------------------------------
void
VISU::ColoredPrs3dCache_i