Re: ALLOCATABLE arrays
From: *** Hendrickson (***.hendrickson_at_att.net)
Date: 01/06/04
- Next message: Dan Nagle: "Re: Complex IF statements"
- Previous message: James Van Buskirk: "Re: Selection akin to SCAN for arrays"
- In reply to: Gus Gassmann: "Re: ALLOCATABLE arrays"
- Next in thread: beliavsky_at_aol.com: "Re: ALLOCATABLE arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 06 Jan 2004 19:40:37 GMT
Gus Gassmann wrote:
>
> Tony Jay wrote:
>
> > > Do I read this right?
> > >
> > > Suppose I declare
> > >
> > > subroutine test
> > > integer :: i
> > > dimension i(k)
> > >
> > > where k is set in a module somewhere. Is it then the case that
> > > a) i gets allocated automatically on entry to test and deallocated
> > > on exit
> > > b) this operation takes (essentially) zero time?
> > >
> > > Is that really all there is to it? I'm afraid to look a gift horse
> > > in the mouth, but this sounds too good to be true!
> > >
> > >
> > Gus,
> >
> > This technique can cause problems if you have insufficient stack size
> > (especially if ou add in a second array at a later date)
> >
> > My understanding is ...
> >
> > If try to create a very large array on the stack and you do not have enough
> > stack (set up in the linking step of the compiler i think) then you program
> > will fail at run time.
> >
> > Allocating on the heap gives you access to a hell of a lot more memory (well
> > as much as your OS can find !)
> >
> > The typical allocate on the stack problem is to test with small problems and
> > then end users use large problems bomb out. You then look a fool (speaking
> > from personal experience)
>
> Hmmmh. 'Nother question, then: Do I get any control in where the array is
> allocated? Here is my current understanding from reading the various
> responses, many of which are over my head, I'm afraid:
>
> Allocatable arrays are allocated on the heap. They can be pretty damn large,
> and I can inquire whether things went OK. The downside is that it is slow.
> Automatic arrays are always allocated on the stack. They are very fast, but
> if the stack overflows, I have no recourse, so I am SOOL. So why use them,
> except for very small arrays? Is there a compiler directive that moves
> automatic arrays to the heap?
Allocatable arrays are >usually< allocated on a heap. They don't
have to be. For relatively simple control flows there is no reason
why a compiler couldn't allocate them on the stack.
Automatic arrays are >usually< allocated on the stack. But, at least a
few years ago, one compiler took a peek at the size and put them on
the heap if they were very large. For reasonable control
flow, heap allocation can be pretty fast, especially in a relative
sense for large arrays.
The problem/feature is that the standard doesn't specify where things
must be put. Only the results of putting them somewhere. Compilers
are free to optimize things as needed. Unfortuntatly, this means
people need to fool around with command line options and system
settings when they move a code around.
*** Hendrickson
- Next message: Dan Nagle: "Re: Complex IF statements"
- Previous message: James Van Buskirk: "Re: Selection akin to SCAN for arrays"
- In reply to: Gus Gassmann: "Re: ALLOCATABLE arrays"
- Next in thread: beliavsky_at_aol.com: "Re: ALLOCATABLE arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]