[Development] QtCore missing check for memory allocation

Olivier Goffart olivier at woboq.com
Mon Mar 9 09:54:36 CET 2015


On Monday 09 March 2015 07:57:18 Knoll Lars wrote:
> The problem is that a non throwing new can’t reliably detect OOM issues.
> Even if we did check the return value of every 'operator new’ call in Qt,
> this would leave us with one big problem that’s more or less impossible to
> solve. The main problem is that we call new inside other constructors (ie.
> Inside another call to operator new).
> 
> The fundamental issue that can’t be solved without exceptions is that this
> should cause the outer operator new to fail (as the inner object didn’t
> get constructed, thus the outer object is not fully constructed and
> usable). But without exceptions there’s no way we can report this back
> through the outer constructor call.


You will be glad to know that the compiler is required to add a null check 
before calling the constructor in case of a noexpect or non-throwing operator 
new.
[C++11 5.3.4 13]




Other than that, if an user of Qt wants a different behavior for malloc and 
new, it is easy enough to use the facilities C++ provides, such as providing a 
global operator new, or overriding malloc. 
If the application provides its own symbol 'malloc', that one will be used.

So Qt does not need to do anything.

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_alloc.cc
Type: text/x-c++src
Size: 521 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150309/a4059e4f/attachment.cc>


More information about the Development mailing list