[Development] QtCore missing check for memory allocation

Koehne Kai Kai.Koehne at theqtcompany.com
Tue Mar 10 09:18:42 CET 2015

> -----Original Message-----
> From: development-bounces+kai.koehne=theqtcompany.com at qt-
> project.org [mailto:development-
> bounces+kai.koehne=theqtcompany.com at qt-project.org] On Behalf Of
> Alex Montgomery
> Sent: Monday, March 09, 2015 6:56 PM
> To: Knoll Lars
> Cc: development at qt-project.org
> Subject: Re: [Development] QtCore missing check for memory allocation
> On Mon, Mar 9, 2015 at 12:57 AM, Knoll Lars
> <Lars.Knoll at theqtcompany.com> wrote:
> > Yes, the best solution IMO is still to use your own malloc and
> > operator new replacements. In addition, OOM handlers on the OS level can
> help.
> Except that dynamically linked Windows Qt applications (read: most) don't
> work this way, so Windows users are left out in the cold. DLLs do not allow
> you to simply replace one new operator across link boundaries. See the
> comments in this Qt bug:
> https://bugreports.qt.io/browse/QTBUG-37395


> Is there any strategy for the large body of Qt developers targeting Windows,
> or is statically linking the only supported method for replacing Qt allocators
> on Windows?

You almost definitely need to recompile Qt , because you can't really override operator new/delete across DLL boundaries (as you already pointed out in the bug report).

Question is whether you can easily force all Qt modules to use a custom operator new / delete ... I've seen suggestions [1] to define an inline operator new / delete (e.g. in qglobal.h), but that seems to violate the standard explicitly stating that "The program's definitions shall not be specified
as inline " (C++14 3). Might nevertheless work though, since there's a high chance that qglobal.h is included in all places where Qt allocates/deallocates memory...



[1]: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ab642c88-2d2d-4f5d-9fd7-2341442d5a46/replacing-new-and-delete-how-to-export-the-implementation?forum=vclanguage)

More information about the Development mailing list