[Qt-interest] Huge memory consumption

Thiago Macieira thiago at kde.org
Wed Jul 7 15:42:00 CEST 2010


On Wednesday 7. July 2010 13.25.43 James Matta wrote:
> A little more investigation leads me to refine my previous question, in
> fact I am now pretty certain that it is not the fault of QFile at all.
> I wrote a plugin to read the data. It allocates memory to store stuff it
> reads and passes a pointer to the main program.
> The main program receives this processes the data and then uses delete[]
> the pointer.
> 
> So my new question is this: Is it possible to free memory in the main
> program that was allocated in a plugin?

Yes, it is.

However, you have to be careful about memory fragmentation.

If you allocate many small chunks, when deallocating, the memory is usually 
not returned to the operating system. It stays with your application for a 
long time -- the allocators usually simply extend the heap (brk(2) on Unix), 
and reducing it depends on the position of currently-allocated blocks.

So if you know that you'll need huge gobs of memory, the recommendation is to 
do large allocations (at least half a megabyte, but I'd go as high as 
recommending 4 MB chunks). 

When you allocate large contiguous sections, the memory allocator usually uses 
the OS's virtual memory allocation routines instead of extending the heap. 
That also means that memory freed can be returned to the operating system.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100707/571ff9f0/attachment.bin 


More information about the Qt-interest-old mailing list