Set different caches size depending on cache type

This commit is contained in:
Atlante45 2015-01-12 15:36:36 -08:00
parent 59c9e0bb50
commit 8415098fc2
7 changed files with 25 additions and 5 deletions

View file

@ -17,7 +17,10 @@
static int animationPointerMetaTypeId = qRegisterMetaType<AnimationPointer>();
AnimationCache::AnimationCache(QObject* parent) :
ResourceCache(parent) {
ResourceCache(parent)
{
const qint64 ANIMATION_DEFAULT_UNUSED_MAX_SIZE = 50 * BYTES_PER_MEGABYTES;
setUnusedResourceCacheSize(ANIMATION_DEFAULT_UNUSED_MAX_SIZE);
}
AnimationPointer AnimationCache::getAnimation(const QUrl& url) {

View file

@ -23,7 +23,8 @@ SoundCache& SoundCache::getInstance() {
SoundCache::SoundCache(QObject* parent) :
ResourceCache(parent)
{
const qint64 SOUND_DEFAULT_UNUSED_MAX_SIZE = 50 * BYTES_PER_MEGABYTES;
setUnusedResourceCacheSize(SOUND_DEFAULT_UNUSED_MAX_SIZE);
}
SharedSoundPointer SoundCache::getSound(const QUrl& url) {

View file

@ -109,9 +109,12 @@ ScriptCache* ScriptCache::getInstance() {
}
ScriptCache::ScriptCache() :
_engine(NULL) {
_engine(NULL)
{
setEngine(new QScriptEngine(this));
const qint64 SCRIPT_DEFAULT_UNUSED_MAX_SIZE = 50 * BYTES_PER_MEGABYTES;
setUnusedResourceCacheSize(SCRIPT_DEFAULT_UNUSED_MAX_SIZE);
}
void ScriptCache::setEngine(QScriptEngine* engine) {

View file

@ -16,6 +16,8 @@
#include <QTimer>
#include <QtDebug>
#include <glm/glm.hpp>
#include "NetworkAccessManager.h"
#include "ResourceCache.h"
@ -70,7 +72,7 @@ QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl&
}
void ResourceCache::setUnusedResourceCacheSize(qint64 unusedResourcesMaxSize) {
_unusedResourcesMaxSize = unusedResourcesMaxSize;
_unusedResourcesMaxSize = glm::clamp(unusedResourcesMaxSize, MIN_UNUSED_MAX_SIZE, MAX_UNUSED_MAX_SIZE);
reserveUnusedResource(0);
}

View file

@ -29,7 +29,14 @@ class Resource;
static constexpr qint64 BYTES_PER_MEGABYTES = 1024 * 1024;
static constexpr qint64 BYTES_PER_GIGABYTES = 1024 * BYTES_PER_MEGABYTES;
// Windows can have troubles allocating that much memory in ram sometimes
// so default cache size at 100 MB on windows (1GB otherwise)
#ifdef Q_OS_WIN32
static constexpr qint64 DEFAULT_UNUSED_MAX_SIZE = 100 * BYTES_PER_MEGABYTES;
#else
static constexpr qint64 DEFAULT_UNUSED_MAX_SIZE = 1024 * BYTES_PER_MEGABYTES;
#endif
static constexpr qint64 MIN_UNUSED_MAX_SIZE = 0;
static constexpr qint64 MAX_UNUSED_MAX_SIZE = 10 * BYTES_PER_GIGABYTES;

View file

@ -30,6 +30,8 @@ const int GeometryCache::UNKNOWN_ID = -1;
GeometryCache::GeometryCache() :
_nextID(0)
{
const qint64 GEOMETRY_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE;
setUnusedResourceCacheSize(GEOMETRY_DEFAULT_UNUSED_MAX_SIZE);
}
GeometryCache::~GeometryCache() {

View file

@ -39,6 +39,8 @@ TextureCache::TextureCache() :
_frameBufferSize(100, 100),
_associatedWidget(NULL)
{
const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE;
setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE);
}
TextureCache::~TextureCache() {