Re: heap allocation of arrays
- From: Norman Yarvin <norman.yarvin@xxxxxxxx>
- Date: Thu, 22 Jun 2006 20:55:53 -0500
In article <1150948966.564129.222540@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<robert.corbett@xxxxxxx> wrote:
Norman Yarvin wrote:
In article <1150702551.395722.174570@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<robert.corbett@xxxxxxx> wrote:
I recently received a request to add an option to Sun Fortran
to force all arrays to be allocated on the heap. Automatic
arrays and other arrays that would normally be allocated on
the stack would be replaced with pointers on the stack.
Space for the arrays would be allocated and deallocated
using malloc and free.
The motivations given for requesting this option were that
the default stack size for most programs is smaller than the
default heap size and that failure to allocate space on the
heap is easier to detect than failure to allocate space on the
stack.
What do you think about such an option?
It doesn't make much sense. If someone has to explicitly activate that
option, they might as well be explicitly increasing the stack size; the
one is as easy to do as the other.
You are assuming that the same person is compiling the program
and running the program. While that is more likely to be true for
Fortran programs than for programs written in other languages, it
is still going to be false in many cases.
No, I was assuming that a user program could increase the stack size, and
thus, instead of adding a compiler option to the makefile, one could add
a call to a stack-size-increase routine to the start of the program.
Even when the user isn't the person compiling the program, normally the
same person controls the code and the makefile.
When I ran into this problem under Linux (in C), I solved it using the
following code:
// Remove the usual limit on stack size, enabling large
// variables to be allocated on the stack.
#include <sys/time.h>
#include <sys/resource.h>
struct rlimit rlim;
rlim.rlim_cur=RLIM_INFINITY;
rlim.rlim_max=RLIM_INFINITY;
setrlimit(RLIMIT_STACK,&rlim);
My impression is that the setrlimit() call is generally available in
modern versions of Unix, but I haven't checked. If it isn't available
for Solaris (or whatever other operating system), then my comments don't
apply to that operating system. But, in any case, it seems inappropriate
for the user to either have to make such a call or have to add a compiler
option to the makefile; instead, automatic allocation of large arrays
should work by default (as it would if, as I was suggesting, the Fortran
runtime initialization code made the above call by default). For array
allocation to crash the program when N gets too large is seriously
pathological behavior.
--
Norman Yarvin http://yarchive.net
.
- References:
- heap allocation of arrays
- From: robert . corbett
- Re: heap allocation of arrays
- From: Norman Yarvin
- Re: heap allocation of arrays
- From: robert . corbett
- heap allocation of arrays
- Prev by Date: Re: Read JPEG Open Source Module??
- Next by Date: Re: problem of block data contained in module
- Previous by thread: Re: heap allocation of arrays
- Next by thread: Re: heap allocation of arrays
- Index(es):
Relevant Pages
|