wxWidgets and memory allocation failures.
Jurko Gospodnetić
jurko_for_boost at mail.inet.hr
Sat Apr 7 04:55:23 PDT 2007
Hi.
I am doing a bit of research into wxWidgets (using wxWidgets 2.8.3)
and noticed that it generally ignores memory allocation failures in
release mode.
In debug mode it generally detects such failures and causes an
assertion failure, but in release mode it seems to simply close its eyes
and hope for a miracle.
For an example see wxStringBase::append().
I tried searching for more information on this on the net and the
wxWidgets documentation but could not find anything relevant. If I
missed it, could someone please point me in the right direction?
And on the subject of ignoring memory allocation failures - I
personally do not agree with this strategy. It seems like an ok strategy
to ignore stuff that may not happen since a set of developer tests would
have caught them if they could, but memory allocation is one of those
things that may go wrong at run-time with no chance for catching it
using any kind of development-time testing.
I realize that such cases are extremely rare and that more often than
not the only possible error handling scenario is to terminate the
application as painlessly as possible. However, I do not think that
'shutting your eyes' and risking undefined behavior (data corruption,
missile launches, whatever...) is the way to go. I rather prefer getting
a std::bad_alloc exception in such cases.
Any thoughts on this? Are there any planned changes intended to deal
with these situations? As it is, I do not feel 'all yummy and safe'
using wxWidgets' 'dynamic allocation' structures in production
applications holding any sort of relevant data. And since the wxString
class is one of those and is used pretty much everywhere throughout
wxWidgets...
WxWidgets seems like a too d*mn good and useful library to just not
use it on such a technicality but what are the alternatives? Ignore the
problem? Always use it in debug mode?
Best regards,
Jurko Gospodnetić
More information about the wx-users
mailing list