MemAlloc not handling out of memory conditions

Archives Forums/BlitzMax Bug Reports/MemAlloc not handling out of memory conditions

grable(Posted 2010) [#1]
MemAlloc should probably check for NULL from malloc, to handle out of memory conditions more gracefully.

Perhaps an exception?

I see that the gc calls malloc a few places as well, which would also need have this check, for consistency.

EDIT: some more background info, though whether this is cause or not i couldnt say.
http://www.blitzbasic.com/Community/posts.php?topic=88691


marksibly(Posted 2010) [#2]
Hi,

> Perhaps an exception?

Except you can't safely use 'New' in out of mem situations - eg: Throw New TOutOfMemEx is kinda paradoxical...

In fact, I believe there really is nothing safe you can do apart from shutdown the app if you run out of memory, as there is just no sane way of telling which Blitz/OS functions require malloc etc themselves - or may in future versions.


Brucey(Posted 2010) [#3]
In fact, I believe there really is nothing safe you can do apart from shutdown the app if you run out of memory

I'd also have to agree. If you run out of memory... your app is screwed basically.
You may think... well, what if I try to flush the GC or something? Well, as Mark says, you never know what parts of that code will require some more RAM before you can free some...

We have an app at work which, from our logs, shows that it is occasionally dying from a bad_alloc exception. That's out-of-memory. It's a bugger to track down the cause, because valgrind doesn't show any leaks. Nightmare.... :-/


marksibly(Posted 2010) [#4]
Hi,

> I'd also have to agree. If you run out of memory... your app is screwed basically.

I guess we could stick something like...

if( !mem ){
MessageBox( "App out of memory - closing" ); //will *probably* work?
abort();
}

...in bbMemAlloc, but it's extra overhead that's not really achieving anything - ie: the app already quits abruptly!

Perhaps in debug mode?


grable(Posted 2010) [#5]
I did manage to allocate some small objects from the GC heap after the System heap was full, but i agree its kinds pointless because there are no guarantees.

Perhaps in debug mode?

That sounds like a reasonable trade-off :)