[Interest] memory fragmentation?
tony at rightsoft.com.au
Tue Aug 21 03:52:25 CEST 2012
I come from a Delphi background. A while ago the FastMM memory allocator
was adopted by the compiler team because it gave very good results for small
allocations. It's not quite SLAB - it only looks at the size, not the type
of object, since all Delphi objects are initialised to zeroes.
I recently needed to optimise XML handling in a Qt application server, and
assumed C++ would have something similar. I was surprised to find that a VS
C++ version was not available, and that changing the allocator requires
nasty run-time patching of linker addresses (?).
In the end I chose Qt 4.8.1 QXmlStreamWriter(QString *). The QByteArray
version seemed the logical choice - but since the API only uses QString,
each call resulted in temporaries being allocated and disposed. It seems
QString is crying out for an appendLatin1(const char *, int len) that
re-allocates the unicode array if necessary, and then does the latin1
conversion without creating a temporary. Doing a single toUtf8 at the end
is also better than calling it a million times.
Another big gain comes from not using literal strings for the element and
attribute tags in loops - create static QStrings, so the latin1 conversion
only happens once.
To Jason: Pre-creating all of the gui's seems extreme? Doesn't it waste a
lot of memory if only a small number of dialogs are open at any time? Also,
unless the dialogs are all static labels, won't populating the controls when
the dialog opens cause allocations?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest