Hello all,
I am using version 4.7.1
I am accessing a QCache in threads with a QFuture. Because I didn't want to slow down cache accesses with mutexes, I did the following:
1)I set maxCost to a really big value which I will never reach
2)I fill the cache with missing objects (kind of polygons in my case) in the main thread
3)I launch the threads, which will use polyCache->object(key) to do their job. Because of step 2 I am 100% sure that all needed polys will be in the QCache. Note that threads do not modify the polys in any way, they just "read" them.
4)When QFuture is finished, I set maxCost to 16384, reducing the cache size but keeping the last accessed polys, ready for the next call.
It works well, except that after a lot of calls of this sequence, the QCache is not cleaned properly, and I end up with much more polys stored in the QCache than 16384...
The documentation says:
int QCache::totalCost() const
Returns the total cost of the object in the cache.
This value is normally below maxCost(), but QCache makes an exception for QT's implicitely shared classes. If a cached object shares its internal data with another instance, QCache may keep the object lying around, possibly contributing to making totalCost() greater than maxCost().
The objects stored in the cache are just a struct, containing some strings, ints and QPolygonFs... I doubt this can be considered as a "Qt's implicitely shared class". Checking the code of Qt I can see that objects are not removed from the cache if qIsDetached returns false, but what exactly qIsDetached is checking is not exactly clear to me...
Also note that if I run this program on a mono-cpu machine, then this problem never occurs. I suspect the problem occurs whenever a QCache:: object() is accessed simultaneously by several threads, but I cannot prove this easily.
Any suggestion on what is not correct in this implementation or what I should do to correctly clean the QCache is welcomed
Thanks



Reply With Quote


)

Bookmarks