[Interest] memory fragmentation?

Adriano Rezende adriano.1.rezende at nokia.com
Tue Aug 21 14:41:15 CEST 2012


On 08/20/2012 05:51 PM, ext Jason H wrote:
> What can be done to combat this in C++/Qt?
>
> Initially I thought there might be some kind of QObject d-ptr magic 
> where the large allocations can be in the private class and 
> re-allocate and copy the private class, without affecting the pointers 
> that the application uses. Then have a function that runs on a QObject 
> tree,  This does not fix the overall issue, but at least it could 
> decrease the the chances of a failed allocation. But for me, this 
> raises as many questions as it solves. Can we guarantee the new 
> allocations are more compact than the old ones? That seems up to the 
> heap manager. I don't know much about that. Also, when to run it? 
> Periodically, or only when an allocation fails?

You will not solve the fragmentation issue in Qt itself, since there is 
no good solution for general purpose but you can extremely reduce the 
problem avoiding the fragmentation for the most critical parts of your 
program.
You can either use an object pool or a memory pool pattern, overloading 
the new operator, but both approaches should be fined tuned for your 
specific use case. I tend to use the former to handle sprites and 
particles in some of my games.


Br,
Adriano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120821/c87cf0e5/attachment.html>


More information about the Interest mailing list