enlightenment
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@796 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
401fdba600
commit
35888376f1
1 changed files with 42 additions and 41 deletions
|
@ -80,7 +80,7 @@ namespace Loki
|
||||||
|
|
||||||
AbstractProduct* release(ProductReturn &pProduct)
|
AbstractProduct* release(ProductReturn &pProduct)
|
||||||
{
|
{
|
||||||
AbstractProduct* pPointer = pProduct;
|
AbstractProduct* pPointer(pProduct);
|
||||||
pProduct=NULL;
|
pProduct=NULL;
|
||||||
return pPointer;
|
return pPointer;
|
||||||
}
|
}
|
||||||
|
@ -170,20 +170,21 @@ namespace Loki
|
||||||
|
|
||||||
void cleanVector()
|
void cleanVector()
|
||||||
{
|
{
|
||||||
|
using namespace std;
|
||||||
clock_t currentTime = clock();
|
clock_t currentTime = clock();
|
||||||
D( std::cout << "currentTime = " << currentTime<< std::endl; )
|
D( cout << "currentTime = " << currentTime<< endl; )
|
||||||
D( std::cout << "currentTime - lastUpdate = " << currentTime - lastUpdate<< std::endl; )
|
D( cout << "currentTime - lastUpdate = " << currentTime - lastUpdate<< endl; )
|
||||||
if(currentTime - lastUpdate > timeValidity)
|
if(currentTime - lastUpdate > timeValidity)
|
||||||
{
|
{
|
||||||
m_vTimes.clear();
|
m_vTimes.clear();
|
||||||
D( std::cout << " is less than time validity " << timeValidity; )
|
D( cout << " is less than time validity " << timeValidity; )
|
||||||
D( std::cout << " so clearing vector" << std::endl; )
|
D( cout << " so clearing vector" << endl; )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
D( std::cout << "Cleaning time less than " << currentTime - timeValidity << std::endl; )
|
D( cout << "Cleaning time less than " << currentTime - timeValidity << endl; )
|
||||||
D( displayVector(); )
|
D( displayVector(); )
|
||||||
Vector::iterator newEnd = remove_if(m_vTimes.begin(), m_vTimes.end(), std::bind2nd(std::less<clock_t>(), currentTime - timeValidity));
|
Vector::iterator newEnd = remove_if(m_vTimes.begin(), m_vTimes.end(), bind2nd(less<clock_t>(), currentTime - timeValidity));
|
||||||
// this rearrangement might be costly, consider optimization
|
// this rearrangement might be costly, consider optimization
|
||||||
// by calling cleanVector in less used onCreate function
|
// by calling cleanVector in less used onCreate function
|
||||||
// ... although it may not be correct
|
// ... although it may not be correct
|
||||||
|
@ -192,13 +193,14 @@ namespace Loki
|
||||||
}
|
}
|
||||||
lastUpdate = currentTime;
|
lastUpdate = currentTime;
|
||||||
}
|
}
|
||||||
|
#ifdef DO_EXTRA_LOKI_TESTS
|
||||||
void displayVector()
|
void displayVector()
|
||||||
{
|
{
|
||||||
std::cout << "Vector : ";
|
std::cout << "Vector : ";
|
||||||
copy(m_vTimes.begin(), m_vTimes.end(), std::ostream_iterator<clock_t>(std::cout, " "));
|
copy(m_vTimes.begin(), m_vTimes.end(), std::ostream_iterator<clock_t>(std::cout, " "));
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
protected:
|
protected:
|
||||||
RateLimitedCreation() : maxCreation(10), timeValidity(CLOCKS_PER_SEC), lastUpdate(clock())
|
RateLimitedCreation() : maxCreation(10), timeValidity(CLOCKS_PER_SEC), lastUpdate(clock())
|
||||||
{}
|
{}
|
||||||
|
@ -260,10 +262,7 @@ namespace Loki
|
||||||
|
|
||||||
bool canCreate()
|
bool canCreate()
|
||||||
{
|
{
|
||||||
if(created>=maxCreation)
|
return !(created>=maxCreation);
|
||||||
return false; // this will call EvictionPolicy::evict()
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCreate()
|
void onCreate()
|
||||||
|
@ -388,7 +387,7 @@ namespace Loki
|
||||||
{
|
{
|
||||||
remove(EH::getLowerBound());
|
remove(EH::getLowerBound());
|
||||||
}
|
}
|
||||||
const char* name(){return "LRU";}
|
const char* name(){return "LRU";}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -515,7 +514,7 @@ namespace Loki
|
||||||
size_type random = static_cast<size_type>((m_vKeys.size()*rand())/int(RAND_MAX + 1));
|
size_type random = static_cast<size_type>((m_vKeys.size()*rand())/int(RAND_MAX + 1));
|
||||||
remove(*(m_vKeys.begin()+random));
|
remove(*(m_vKeys.begin()+random));
|
||||||
}
|
}
|
||||||
const char* name(){return "random";}
|
const char* name(){return "random";}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -571,21 +570,22 @@ namespace Loki
|
||||||
|
|
||||||
void onDebug()
|
void onDebug()
|
||||||
{
|
{
|
||||||
std::cout << "############################" << std::endl;
|
using namespace std;
|
||||||
std::cout << "## About this cache " << this << std::endl;
|
cout << "############################" << endl;
|
||||||
std::cout << "## + Created objects : " << created << std::endl;
|
cout << "## About this cache " << this << endl;
|
||||||
std::cout << "## + Fetched objects : " << fetched << std::endl;
|
cout << "## + Created objects : " << created << endl;
|
||||||
std::cout << "## + Destroyed objects : " << created - allocated << std::endl;
|
cout << "## + Fetched objects : " << fetched << endl;
|
||||||
std::cout << "## + Cache hit : " << hit << std::endl;
|
cout << "## + Destroyed objects : " << created - allocated << endl;
|
||||||
std::cout << "## + Cache miss : " << fetched - hit << std::endl;
|
cout << "## + Cache hit : " << hit << endl;
|
||||||
std::cout << "## + Currently allocated : " << allocated << std::endl;
|
cout << "## + Cache miss : " << fetched - hit << endl;
|
||||||
std::cout << "## + Currently out : " << out << std::endl;
|
cout << "## + Currently allocated : " << allocated << endl;
|
||||||
std::cout << "############################" << std::endl;
|
cout << "## + Currently out : " << out << endl;
|
||||||
|
cout << "############################" << endl;
|
||||||
if(fetched!=0){
|
if(fetched!=0){
|
||||||
std::cout << "## Overall efficiency " << 100*double(hit)/fetched <<"%"<< std::endl;
|
cout << "## Overall efficiency " << 100*double(hit)/fetched <<"%"<< endl;
|
||||||
std::cout << "############################" << std::endl;
|
cout << "############################" << endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFetch()
|
void onFetch()
|
||||||
|
@ -700,16 +700,16 @@ namespace Loki
|
||||||
AbstractProduct* const getPointerToObjectInContainer(ObjVector &entry)
|
AbstractProduct* const getPointerToObjectInContainer(ObjVector &entry)
|
||||||
{
|
{
|
||||||
if(entry.empty()) // No object available
|
if(entry.empty()) // No object available
|
||||||
{ // the object will be created in the calling function.
|
{ // the object will be created in the calling function.
|
||||||
// It has to be created in the calling function because of
|
// It has to be created in the calling function because of
|
||||||
// the variable number of parameters for CreateObject(...) method
|
// the variable number of parameters for CreateObject(...) method
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // returning the found object
|
{ // returning the found object
|
||||||
AbstractProduct* pObject = entry.back();
|
AbstractProduct* pObject(entry.back());
|
||||||
assert(pObject!=NULL);
|
assert(pObject!=NULL);
|
||||||
entry.pop_back();
|
entry.pop_back();
|
||||||
return pObject;
|
return pObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1146,13 +1146,14 @@ namespace Loki
|
||||||
/// display the cache configuration
|
/// display the cache configuration
|
||||||
void displayCacheType()
|
void displayCacheType()
|
||||||
{
|
{
|
||||||
std::cout << "############################" << std::endl;
|
using namespace std;
|
||||||
std::cout << "## Cache configuration" << std::endl;
|
cout << "############################" << endl;
|
||||||
std::cout << "## + Encapsulation " << NP::name() << std::endl;
|
cout << "## Cache configuration" << endl;
|
||||||
std::cout << "## + Creating " << CP::name() << std::endl;
|
cout << "## + Encapsulation " << NP::name() << endl;
|
||||||
std::cout << "## + Eviction " << EP::name() << std::endl;
|
cout << "## + Creating " << CP::name() << endl;
|
||||||
std::cout << "## + Statistics " << SP::name() << std::endl;
|
cout << "## + Eviction " << EP::name() << endl;
|
||||||
std::cout << "############################" << std::endl;
|
cout << "## + Statistics " << SP::name() << endl;
|
||||||
|
cout << "############################" << endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace Loki
|
} // namespace Loki
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue