[Development] QtCore missing check for memory allocation

Thiago Macieira thiago.macieira at intel.com
Thu Feb 26 19:39:46 CET 2015


On Wednesday 25 February 2015 21:29:31 Marc Mutz wrote:
> > -- why should now people have a slower library because 
> > of all those checks?
> 
> Q_CHECK_PTR does not necessarily make the library slower. It only needs to
> be  applied to malloc/calloc and nothrow operator new, because ordinary new
> already throws. We can port such code to normal operator new instead.

Writing the checks is useless unless we also write the code to recover from 
such situations. For the case of exceptions, we need to make sure that the 
code survives stack unwinding somewhat gracefully until the exception handler. 
For the case of nullptrs, we need to ensure that functions exit indicating 
errors or setting error states in the objects.

The checks themselves may not be the performance bottleneck. Rearranging the 
code around to make sure that the check is useful is the bottleneck.

Unless we take the suggestion elsewhere in this thread to reliably and 
immediately terminate the application.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list