Is "Out of Memory" a recoverable error?

Stewart Gordon smjg_1998 at yahoo.com
Sat Dec 6 16:04:28 PST 2008


"Don" <nospam at nospam.com> wrote in message 
news:gh3et3$13tm$1 at digitalmars.com...
> Walter Bright wrote:
>> I asked this over on stackoverflow.com to see what people using other 
>> languages have to say, as well as the D community. The reason I ask is to 
>> see if memory allocation can be allowed in functions marked "nothrow".
>>
>> http://stackoverflow.com/questions/333736/is-out-of-memory-a-recoverable-error
> I don't think it can be recoverable. Or rather, if it is recoverable, it 
> shouldn't have happened in the first place.
>
> As far as I can tell, the only thing you could do to recover from an 
> out-of-memory condition is (1) to free some memory, or (2) to switch to an 
> algorithm which doesn't need as much memory.
>
> Strategy (1):
> Windows used to have a WM_COMPACTING message (maybe it still does) which 
> was sent when the system was running low on memory. In D, you could 
> imagine a similar sort of system callback, which is called when memory is 
> short -- it means, free some memory now, otherwise you'll get an out of 
> memory error.
> This is much simpler and more powerful than catching an 
> OutOfMemoryException, freeing some memory, and then repeating what you 
> were doing.

There ought to be a means of giving the GC a function to call whenever it's 
about to do its business.

> Strategy (2):
> If you've got a second algorithm to use, why weren't you checking 
> available memory, and choosing the correct algorithm in the first place?
<snip>

Because there's no documented function in Phobos for checking how much 
memory is available, possibly?

Stewart.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies 
on the 'group where everybody may benefit. 




More information about the Digitalmars-d mailing list