Making KMemoryInfo useful (Re: KDE/kdelibs/kdecore)

Parker Coates parker.coates at kdemail.net
Sat Mar 20 20:19:25 GMT 2010


On Sat, Mar 20, 2010 at 15:54, Lubos Lunak wrote:
> On Saturday 20 of March 2010, Albert Astals Cid wrote:
>> A Dissabte, 20 de març de 2010, Lubos Lunak va escriure:
>> >  Let's continue only on k-c-d.
>> >
>> > ... Some bashing ...
>
>  I apologize, it wasn't meant to be. And I don't think it was that bad,
> although quite possibly I have already seen enough cases of memory measuring
> going wrong and really wasn't happy to see kdelibs getting a tool to do it
> even easier.
>
>> Ok, so you are the smart dude, how do we solve the problem with
>> applications wanting to know how much memory they can use?
>
>  See attachment, that is how I would envision the class. I didn't update the
> docs and didn't bother with implementing requestMemory() for real, but
> otherwise I would hope this is quite clear even without docs:
>
> ...
> connect( &memoryInfo, SIGNAL( releaseMemoryRequest( size_t )), this, SLOT(
> releaseMemory( size_t )));
> ...
>
> if( I_want_100M_for_cache && memoryInfo.update( KMemoryInfo::AvailableRam ) &&
> memoryInfo.detail( KMemoryInfo::AvailableRam ) >= 100 * 1024 * 1024 )
>   ...
>
> if( I_need_300M_to_work )
>    {
>    if( memoryInfo.update( KMemoryInfo::AvailableMemory ) &&
> memoryInfo.detail( KMemoryInfo::AvailableMemory ) >= 300 * 1024 * 1024 )
>       do_work();
>    else if( memoryInfo.requestMemory( 300 * 1024 * 1024 ))
>        do_work();
>    ...
>
> void Foo::releaseMemory( size_t amount )
>    {
>    size_t freed = 0;
>    while( !cachedObjects.isEmpty() && freed < amount )
>        {
>        freed += cachedObjects.first()->size();
>        delete cachedObjects.takeFirst();
>        }
>    }
>
>  Any problems with that?
>
>  Special bonus: 4.5 release blahblah can somewhere include something along the
> lines of "KDE platform now includes support for applications making use of
> additional memory when available and keeping their memory usage low when
> running short on memory or on low-memory systems". And if people get it wrong
> as is the usual case for anything memory-related, with a little luck they may
> at least get it wrong the favourable way for a change ("well, yes, my KDE
> uses 800M RAM, but that's only because my computer has 2G RAM, see?").

Possibly naive question: Is it not likely that applications would get
into pushing matches, constantly requesting that others free up RAM
for them to use?

Parker




More information about the kde-core-devel mailing list