wxWidgets and memory allocation failures.
Jurko Gospodnetić
jurko_for_boost at mail.inet.hr
Sat Apr 7 14:55:18 PDT 2007
Hi.
> Unfortunately it's not a simple problem and I don't have any satisfactory
> answer to it. We could call some user-defined function when memory
> allocation fails and wash our hands of the issue by saying that we allow
> the programmer to do whatever is most appropriate in each particular case.
> But this wouldn't be really helpful neither. And I don't know what would.
Thinking about this some more, there is not much freedom available in
handling this case. It is definitely an error, and an error that should
not cause 'undefined behavior'. As an error it may be handled by either:
1. terminating the application
2. returning an error code (either global/thread-local variable,
return value or an error-code parameter).
3. throwing an exception.
Before this handling wxWidgets could call an application defined
function, possibly allowing the application callback to free up some
memory and have wxWidgets retry the previously failed memory allocation
instead of simply failing.
Since wxWidgets does not use exceptions option 3 is out.
Returning an error code would most likely (and I am only making an
educated guess here) have an enormous impact on the current interface
and implementation. For example, you would no longer be able to to
simple operations like string appending using chained operator<<() calls
if they remain implemented in the same way as they are now. So that
takes option 2 most likely out of the picture as well.
And all you are left with is option 1 (with possibly an application
defined function call as described above).
Hope this helps..
Best regards,
Jurko Gospodnetić
More information about the wx-users
mailing list