On 10/29/2011 7:19 PM, Vladimir Panteleev wrote:
On Sun, 30 Oct 2011 01:56:23 +0300, Timon Gehr <timon.g...@gmx.ch> wrote:

You could use catch(Error err) or catch(OutOfMemoryError err) or not
catch the Error at all.

I'll use OutOfMemoryError. If any other error occurs, it's probably best to let the function fail.

Note that (IIRC) an OutOfMemoryError will be thrown only when:
1) There is no space on the managed heap
2) A garbage collection cycle failed to free enough memory for the
requested allocation
3) The operating system could not allocate any more memory, even from swap.

Some operating systems (Windows) will even expand the swap file
automatically when it nears being full.

I don't think that there's any point in doing anything sensible in an
OutOfMemory handler.


32-bit processes on Windows can only have up to 2GiB of addressable memory. Even if there's enough "available" memory, there may not be a large enough area of contiguous free space. I've gotten out of memory errors when working in D.

I handle the error because I can. My algorithm doesn't require any minimum amount of memory to be allocated, so I can reduce the memory usage for a small loss in performance.

Reply via email to