[KPhotoAlbum] Bug in image cache size computation

Robert Krawitz rlk at alum.mit.edu
Sun Sep 27 15:43:02 BST 2015


On Sun, 27 Sep 2015 04:42:25 -0400, Miika Turkia wrote:
> On Sat, Sep 26, 2015 at 7:55 PM, Robert Krawitz <rlk at alum.mit.edu> wrote:
>> The number of items in the image cache is computed incorrectly if the
>> image cache size is 2048 MB or greater; it's effectively zero due to
>> signedness problems.  Performance is much better with this fix.
>>
>> Also, why the hard upper limit of 4096 MB?  I have 16 GB of RAM in my
>> laptop, and might as well take advantage of it.
>>
>> diff --git a/Viewer/ImageDisplay.cpp b/Viewer/ImageDisplay.cpp
>> index 1775efb..77be9a9 100644
>> --- a/Viewer/ImageDisplay.cpp
>> +++ b/Viewer/ImageDisplay.cpp
>> @@ -567,7 +567,7 @@ void Viewer::ImageDisplay::setImageList( const DB::FileNameList& list )
>>
>>  void Viewer::ImageDisplay::updatePreload()
>>  {
>> -    const int cacheSize = ( Settings::SettingsData::instance()->viewerCacheSize() * 1024 * 1024 ) / (width()*height()*4);
>> +    const int cacheSize = (int) ((long long) ( Settings::SettingsData::instance()->viewerCacheSize() * 1024ll * 1024ll ) / (width()*height()*4));
>>      bool cacheFull = (m_cache.count() > cacheSize);
>
> You really had me fooled with this one. Not easy at all to decipher,
> what is going on before getting the morning fix of caffeine. Anyway,
> you could as well change to unsigned cacheSize while you are at it.
> But that would probably take a bit more effort to change on the
> required other places.

I tried that, but that did have some upstream problems, at least one
related to Qt (QMap.count() returns an int, believe it or not) and I
didn't take it any further.  Another, perhaps better, option would be
to make cacheSize a long long.
-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

***  MIT Engineers   A Proud Tradition   http://mitathletics.com  ***
Member of the League for Programming Freedom  --  http://ProgFree.org
Project lead for Gutenprint   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the Kphotoalbum mailing list