Making KMemoryInfo useful (Re: KDE/kdelibs/kdecore)
Lubos Lunak
l.lunak at suse.cz
Sat Mar 20 19:54:59 GMT 2010
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?").
--
Lubos Lunak
openSUSE Boosters team, KDE developer
l.lunak at suse.cz , l.lunak at kde.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: util.patch
Type: text/x-diff
Size: 7999 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100320/d8880b7c/attachment.patch>
More information about the kde-core-devel
mailing list