[Kst] RE: Kst Digest, Vol 12, Issue 33
staikos at kde.org
Wed Apr 28 22:57:49 CEST 2004
On Wednesday 28 April 2004 16:36, Barth Netterfield wrote:
> On April 28, 2004 04:26 pm, Andrew Walker wrote:
> > I still believe that at some point
> > we have to confirm all memory allocations and fail
> > gracefully where necessary.
> In our case, I tend to agree, assuming it can even be done.
> George, do you know the state of checking for memory allocations in modern
> linuxes... I seem to remember that in the past, you could get success on
> malloc, but fail on use. Since we are an app that may suddenly (and
> reasonably some might say) ask for more memory than exists, it really would
> be great to generate a graceful 'I'm sorry dave...' and keep running,
> rather than the typical bring down the system as often happens in
It's not really possible. You're right, Linux will tell you "OK" when you
allocate more memory than available, then you could have problems later. If
you are trying to catch a failure of new[some_big_number], it will only fail
if something bad happened, and will likely fail for new[some_small_number]
too. If it does fail, what will you do?
1) pop up dialog? no, that will do lots of new
2) save work? no, even more new
3) free random data or objects?
Also new does or doesn't return null on failure depending on if
-fno-exceptions is used. You will need to cover both cases or explicitly
forbid/force exception support in Kst.
If you get to the point where the OS returns failure on malloc, you're
probably deep into swap with a thrashing machine anyway. It's generally a
no-win situation as far as I can tell. Oh, and KDE doesn't check for null
anywhere anyway. I think the best handler we'd be capable of is:
printf("About to crash!\n");
KDE Developer http://www.kde.org/
Staikos Computing Services Inc. http://www.staikos.net/
More information about the Kst