Capturing automatic array memory allocation failure

Capturing automatic array memory allocation failure


I gave a subroutine that uses automatic arrays. In some (rare) occasions, there isn't enough memory and the call to the routine generates a "stack overflow" error. The automatic arrays are too large.  Is there a way to trap the memoray allocation failure within the routine, so that I can set a error flag and do a graceful return? I being careful here to say "automatic arrays", not "allocatable arrays." I don't want to use allocatable arrays in this routine.


4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The options to fix the stack overflow are to either increase your stacksize or to tell the compiler to allocate automatic arrays on the heap rather than the stack.  Unfortunately, I'm not familiar with exactly where these options are in the VC shell, though I would expect someone will follow up and let you know where to find those.


Making the array allocatable would solve the problem. I'm not sure why you don't want to use ALLOCATE. It is a more robust solution, compared to using the stack.


The heap allocation option is Fortran > Optimization > Heap Arrays - set this to zero. Your problem will likely be solved. There is no way to trap stack overflow and do anything graceful with it.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today