PDA

View Full Version : sharing QPixmap object between QGraphicsPixmapItems



franki
13th August 2012, 14:18
Hi all,

This is about phone application, tested on N8
I have lets say 40 objects derived from QGraphicsPixmapItem, these object lets name them "icon", are created in single class "iconView" during application start, every "icon" object uses 5 QPixmaps to visualize its state. Is it worth to load these QPixmaps once in iconView class before creating "icon" objects, and only pass pointers to loaded QPixmaps to each "icon" object, instead of loading every pixmap inside "icon" object multiple times ?
Every pixmap is about 10k in size, so they are small, but 40*5*10k=2MB, still not much, however, I have also some amount of other objects and recently I had to change epocheapsize in .pro file, because app didn't start.
So is it worth an effort to share QPixmap between QGraphicsItems or just epochepasize values are really small by default, and I should increase them and forget about issue?

best regards
Marek

spirit
13th August 2012, 14:21
Use QPixmapCache.

ChrisW67
15th August 2012, 00:12
QPixmap is implicitly shared, so assigning the same QPixmap (by value) in n places does not result in n copies of the pixmap data: they share the same bulk data. If you modify one of the copies then that instance is split from the others and the data is copied at that point in time. Depending on whether you have 40 * 5 distinct images or 40 sets of 5 identical (copied) images then you may not have the memory consumption you are expecting.