Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2006
Questions about QCache


Message 1 in thread

Nobody answered my last QCache question, so I'm reposting it but 
slimming it down.  In QCache, how can you touch an object?  This means I 
want to make the object (already in the cache) the most recently used 
object.  Is calling insert again on this object sufficient to make it 
the mru object?  If I call contains on an object, is that sufficient? 
Also, I'm still concerned about the documentation for insert on a 
QCache.  The documentation reads: "if cost is greater than maxCost(), 
the object will be deleted immediately."  Shouldn't this read AN object 
will be removed (namely, the least recently used object), not THE Object 
you're currently inserting?  Thanks,

Chris

--
 [ signature omitted ] 

Message 2 in thread

On 12/11/06, Chris Portka <cportka@xxxxxxxxxxxxxxx> wrote:
> Nobody answered my last QCache question, so I'm reposting it but
> slimming it down.  In QCache, how can you touch an object?  This means I
> want to make the object (already in the cache) the most recently used
> object.  Is calling insert again on this object sufficient to make it
> the mru object?  If I call contains on an object, is that sufficient?
> Also, I'm still concerned about the documentation for insert on a
> QCache.  The documentation reads: "if cost is greater than maxCost(),
> the object will be deleted immediately."  Shouldn't this read AN object
> will be removed (namely, the least recently used object), not THE Object
> you're currently inserting?  Thanks,

I don't know about the hits, but I guess the documentation is right,
why cache an object that is greater than maxCost? It will be thrown
out of the cache on the next object anyway.

-- 
 [ signature omitted ] 

Message 3 in thread

Robin Ericsson wrote:
> On 12/11/06, Chris Portka <cportka@xxxxxxxxxxxxxxx> wrote:
>> Nobody answered my last QCache question, so I'm reposting it but
>> slimming it down.  In QCache, how can you touch an object?  This means I
>> want to make the object (already in the cache) the most recently used
>> object.  Is calling insert again on this object sufficient to make it
>> the mru object?  If I call contains on an object, is that sufficient?
>> Also, I'm still concerned about the documentation for insert on a
>> QCache.  The documentation reads: "if cost is greater than maxCost(),
>> the object will be deleted immediately."  Shouldn't this read AN object
>> will be removed (namely, the least recently used object), not THE Object
>> you're currently inserting?  Thanks,
> 
> I don't know about the hits, but I guess the documentation is right,
> why cache an object that is greater than maxCost? It will be thrown
> out of the cache on the next object anyway.

That doesn't make any sense since when the maxCost is exceeded, it 
should be deleting the least recently used objects (as per the QCache 
docs for 4.2) and one you just added to the cache should be considered 
most recently used so it wouldn't be the one picked to be deleted.  If 
QCache is deleting the object you just added, it seems a rather poor 
design to me and I hope the docs are wrong.  If this is how it works, I 
hope they will fix it since it *really* makes no sense.

--
 [ signature omitted ] 

Message 4 in thread

Hi Brad,

> 
> That doesn't make any sense since when the maxCost is exceeded, it 
> should be deleting the least recently used objects (as per the QCache 
> docs for 4.2) and one you just added to the cache should be considered 
> most recently used so it wouldn't be the one picked to be deleted.  If 
> QCache is deleting the object you just added, it seems a rather poor 
> design to me and I hope the docs are wrong.  If this is how it works, I 
> hope they will fix it since it *really* makes no sense.

I don't get you. If you have a cache with a maxCost of, say, 100, put 50 
items with a cost of one each into it, and then want to add an item with 
a cost of 150.

According to the docs QCache throws away the newly added item only. What 
you seem to want is to throw away all objects, those cached as well as 
the new one.

I prefer the way the trolls do it. Note: a cache is *not* a 
least-recently-used list!

Or did I misunderstand you?
/eno

--
 [ signature omitted ] 

Message 5 in thread

Enrico Thierbach wrote:
> Hi Brad,
> 
>>
>> That doesn't make any sense since when the maxCost is exceeded, it 
>> should be deleting the least recently used objects (as per the QCache 
>> docs for 4.2) and one you just added to the cache should be considered 
>> most recently used so it wouldn't be the one picked to be deleted.  If 
>> QCache is deleting the object you just added, it seems a rather poor 
>> design to me and I hope the docs are wrong.  If this is how it works, 
>> I hope they will fix it since it *really* makes no sense.
> 
> I don't get you. If you have a cache with a maxCost of, say, 100, put 50 
> items with a cost of one each into it, and then want to add an item with 
> a cost of 150.
> 
> According to the docs QCache throws away the newly added item only. What 
> you seem to want is to throw away all objects, those cached as well as 
> the new one.
> 
> I prefer the way the trolls do it. Note: a cache is *not* a 
> least-recently-used list!
> 
> Or did I misunderstand you?
> /eno
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

I think I understand now.  There is ambiguity in the wording for insert, 
I thought it meant "if [total] cost is greater than maxCost" whereas 
you're supposed to infer that it means "if [the object your inserting's] 
cost is greater than maxCost]".  Also - what do you mean a cache is not 
an LRU list?  The documentation explicitly states that internally, an 
LRU list is used to store the items in a cache.  Therefore, I want to 
know - how do I make this internal LRU list have a specific item as the 
most recently used item?  Is calling contains sufficient?  What about 
re-inserting the item?
Chris

--
 [ signature omitted ] 

Message 6 in thread

On Thursday 14 December 2006 11:09 am, Chris Portka wrote:
> Enrico Thierbach wrote:
> > Hi Brad,
> >
> >> That doesn't make any sense since when the maxCost is exceeded, it
> >> should be deleting the least recently used objects (as per the QCache
> >> docs for 4.2) and one you just added to the cache should be considered
> >> most recently used so it wouldn't be the one picked to be deleted.  If
> >> QCache is deleting the object you just added, it seems a rather poor
> >> design to me and I hope the docs are wrong.  If this is how it works,
> >> I hope they will fix it since it *really* makes no sense.
> >
> > I don't get you. If you have a cache with a maxCost of, say, 100, put 50
> > items with a cost of one each into it, and then want to add an item with
> > a cost of 150.
> >
> > According to the docs QCache throws away the newly added item only. What
> > you seem to want is to throw away all objects, those cached as well as
> > the new one.
> >
> > I prefer the way the trolls do it. Note: a cache is *not* a
> > least-recently-used list!
> >
> > Or did I misunderstand you?
> > /eno

I had always assumed the docs meant that Once the maxCost of the cache was 
exceeded, it would start removing/destroying objects (hopefully the least 
used objects) to make the new one fit.

> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
>
> I think I understand now.  There is ambiguity in the wording for insert,
> I thought it meant "if [total] cost is greater than maxCost" whereas
> you're supposed to infer that it means "if [the object your inserting's]
> cost is greater than maxCost]".  Also - what do you mean a cache is not
> an LRU list?  The documentation explicitly states that internally, an
> LRU list is used to store the items in a cache.  Therefore, I want to
> know - how do I make this internal LRU list have a specific item as the
> most recently used item?  Is calling contains sufficient?  What about
> re-inserting the item?
> Chris
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

-- 
 [ signature omitted ] 

Message 7 in thread

Enrico Thierbach wrote:
> Hi Brad,
> 
>>
>> That doesn't make any sense since when the maxCost is exceeded, it 
>> should be deleting the least recently used objects (as per the QCache 
>> docs for 4.2) and one you just added to the cache should be considered 
>> most recently used so it wouldn't be the one picked to be deleted.  If 
>> QCache is deleting the object you just added, it seems a rather poor 
>> design to me and I hope the docs are wrong.  If this is how it works, 
>> I hope they will fix it since it *really* makes no sense.
> 
> I don't get you. If you have a cache with a maxCost of, say, 100, put 50 
> items with a cost of one each into it, and then want to add an item with 
> a cost of 150.
> 
> According to the docs QCache throws away the newly added item only. What 
> you seem to want is to throw away all objects, those cached as well as 
> the new one.

I see what you mean and understand now what the docs are trying to say. 
  From what I read (and I'm not the only one), it sounded like if the 
max cost was 100 and I started inserting items with a cost of 1 it would 
work fine up to and including the 100th item and from then on each one I 
inserted would make it over its max cost so it would immediately be 
deleted.  This is what didn't seem to be very useful and what I thought 
the docs were saying it would do.

> I prefer the way the trolls do it. Note: a cache is *not* a 
> least-recently-used list!

Well the docs say that when you insert an object and its now over the 
max cost, the least recently used objects will be deleted from the cache 
to get it back under the max cost.  So there has to be a least recently 
used list in there somewhere!  It is only mentioned in one place in the 
docs though and oddly enough its not mentioned in the insert method 
docs.  The insert method docs also don't say explicitly that a newly 
inserted object is considered to be most recently used or not. 
Basically most of the rules of how the LRU is managed are not given 
which is what is causing the confusion.

> Or did I misunderstand you?

Well I think I misunderstood the docs.  Something like "If the cost of 
the object being inserted is greater than the max cost, the object will 
not be inserted but the method will return true as if it had." would 
explain it more clearly to me.  And it should also give more info on the 
LRU handling that insert does like mention that after the object is 
inserted, if the cost of all the objects is now over the max cost it 
will start deleting the least recently used objects until the total cost 
is below the max cost.  To know whats going to happen here though, you 
need to know how the object being inserted is to be treated.  If it is 
considered most recently used, then you know your object isn't going to 
be immediately throw back out of the cache in this situation.

--
 [ signature omitted ] 

Message 8 in thread

Hi Brad,

> I see what you mean and understand now what the docs are trying to say. 
>  From what I read (and I'm not the only one), it sounded like if the max 
> cost was 100 and I started inserting items with a cost of 1 it would 
> work fine up to and including the 100th item and from then on each one I 
> inserted would make it over its max cost so it would immediately be 
> deleted.  This is what didn't seem to be very useful and what I thought 
> the docs were saying it would do.
> 

My docs here (Qt 4.2.0) say:

"In particular, if cost is greater than maxCost(), the object will be 
deleted immediately."

whereas cost refers to the parameter to insert(...) and maxCost() to the 
cache's maxCost property.
In particular, it doesn't say "if the new totalCost() of the cache is 
greater than maxCost() the object will be deleted." which would be the 
scenarion you describe.

The docs seem absolutely clear to me here. However, if you and some 
other people misunderstand this you should file a bug with the trolls 
asking for further explanation in the docs.


>> I prefer the way the trolls do it. Note: a cache is *not* a 
>> least-recently-used list!
> 
> Well the docs say that when you insert an object and its now over the 
> max cost, the least recently used objects will be deleted from the cache 
> to get it back under the max cost.  So there has to be a least recently 
> used list in there somewhere! 

While this is true in a way it is - in my mind - an implementation 
detail where one shouldn't rely onto. For example, if you put 50 items 
of cost 1 and one item of cost 50 into a cache of maxCost 100 and add 
the next item, QCache could decide to throw away the 50-cost item and 
let all other live - regardless of the order in which these items had 
been inserted.

This would break neither an expected cache behaviour and nor the 
interface docs. This is what I meant with my statement.

If you need an LRU list - when talking about caches with a policy where 
older items get always deleted before newer ones - then you should do it 
yourself. Its pretty straightforward, I guess.

/eno



--
 [ signature omitted ] 

Message 9 in thread

"Use the source, Luke" (SW or something)
I don't see what all the arguing for, is the source is just there. And
it simple enought - even simpler then reading docs.
QCache - is a just a simple LRU with the hash for faster lookups.
Whenever the item is accessed (QCache::object and QCache::operator[])
the item is moved to the front of LRU. When item is inserted, and
there not enough "space" the least recently used items (the back of
LRU list are removed, until enough space if freed to fit the new item.
And, as said in docs, if newly inserted item is larger than total
cost, it deleted immediately and never inserted into cache.

On 12/15/06, Enrico Thierbach <troll@xxxxxxxxxxxx> wrote:
> Hi Brad,
>
> > I see what you mean and understand now what the docs are trying to say.
> >  From what I read (and I'm not the only one), it sounded like if the max
> > cost was 100 and I started inserting items with a cost of 1 it would
> > work fine up to and including the 100th item and from then on each one I
> > inserted would make it over its max cost so it would immediately be
> > deleted.  This is what didn't seem to be very useful and what I thought
> > the docs were saying it would do.
> >
>
> My docs here (Qt 4.2.0) say:
>
> "In particular, if cost is greater than maxCost(), the object will be
> deleted immediately."
>
> whereas cost refers to the parameter to insert(...) and maxCost() to the
> cache's maxCost property.
> In particular, it doesn't say "if the new totalCost() of the cache is
> greater than maxCost() the object will be deleted." which would be the
> scenarion you describe.
>
> The docs seem absolutely clear to me here. However, if you and some
> other people misunderstand this you should file a bug with the trolls
> asking for further explanation in the docs.
>
>
> >> I prefer the way the trolls do it. Note: a cache is *not* a
> >> least-recently-used list!
> >
> > Well the docs say that when you insert an object and its now over the
> > max cost, the least recently used objects will be deleted from the cache
> > to get it back under the max cost.  So there has to be a least recently
> > used list in there somewhere!
>
> While this is true in a way it is - in my mind - an implementation
> detail where one shouldn't rely onto. For example, if you put 50 items
> of cost 1 and one item of cost 50 into a cache of maxCost 100 and add
> the next item, QCache could decide to throw away the 50-cost item and
> let all other live - regardless of the order in which these items had
> been inserted.
>
> This would break neither an expected cache behaviour and nor the
> interface docs. This is what I meant with my statement.
>
> If you need an LRU list - when talking about caches with a policy where
> older items get always deleted before newer ones - then you should do it
> yourself. Its pretty straightforward, I guess.


-- 
 [ signature omitted ] 

Message 10 in thread

Hi,

> "Use the source, Luke" (SW or something)
> I don't see what all the arguing for, is the source is just there. And
> it simple enought - even simpler then reading docs.

The source may change without notice. The documentation is a sort of 
contract, it describes what to expect from the API.

--
 [ signature omitted ] 

Message 11 in thread

On 12/18/06, Dimitri <dimitri@xxxxxxxxxxxxx> wrote:
> > "Use the source, Luke" (SW or something)
> > I don't see what all the arguing for, is the source is just there. And
> > it simple enought - even simpler then reading docs.
>
> The source may change without notice. The documentation is a sort of
> contract, it describes what to expect from the API.

Theoretically I agree, but in practice implementation rarely changes
and documentation is not enough in some cases. For example, Qt
documentation rarely specifies complexity constrains, and one need to
figure them out from the code. Sometimes one can even discover things
in a code that never mentioned in documentation (reminds me of
QPixmapCache where I've discovered that it evicts items automatically
over time - even posted question on list that never been answered).
Besides, Qt is written well and clean, and it always nice to read good code :)

-- 
 [ signature omitted ] 

Message 12 in thread

Pavel Antokolsky aka Zigmar wrote:
> "Use the source, Luke" (SW or something)
> I don't see what all the arguing for, is the source is just there. And
> it simple enought - even simpler then reading docs.
> QCache - is a just a simple LRU with the hash for faster lookups.
> Whenever the item is accessed (QCache::object and QCache::operator[])
> the item is moved to the front of LRU. When item is inserted, and
> there not enough "space" the least recently used items (the back of
> LRU list are removed, until enough space if freed to fit the new item.
> And, as said in docs, if newly inserted item is larger than total
> cost, it deleted immediately and never inserted into cache.

Well, we can go on like this for another few weeks here. However, I find 
no point in telling us again and again that, yes,

 > And, as said in docs, if newly inserted item is larger than total
 > cost, it deleted immediately and never inserted into cache.

While this violates a LRU behaiour: you would want the old items deleted 
too, right? - it is sensible for a cache thing. This is what I wanted to 
say in the first place: Want an LRU? implement an LRU. Want a cache? Use 
QCache, don't rely on LRU functionality, but hope that the trolls have 
implemented a reasonably caching strategy. That's all.

/eno

--
 [ signature omitted ]