Re: Stack or Heap



On 19 nov, 21:58, PGK <graham.k...@xxxxxxxxx> wrote:
Hi all,

I find I'm guessing at this quite a lot, and wondered if you could
help me. When are arrays allocated on the heap, and when on the stack?
Is this specified by the standard or is the implementation free to
choose? Is a Fortran stack typically larger than a C stack?

Graham

Usually, automatic arrays, as well as local non saved scalar
variables, are allocated on the stack whereas allocated variables
(declared allocatable or pointer) are allocated on the heap.

But this is implementation free and the stack, as far as I know, is
not a FORTRAN or C concept by an operating system concept. On UNIX
computers, I generally declare the stack size as follows :

ulimit -s unlimited

In addition, a compiler usually does not (cannot ?) check the
remaining free stack length : so I tends to avoid the use of large
automatic arrays. Notice that the strategy of the compiler may be
often modified by specific options.
.



Relevant Pages

  • Re: Stack or Heap
    ... When are arrays allocated on the heap, ... Is a Fortran stack typically larger than a C stack? ... Quite often automatic arrays will be allocated on the heap, as well, ...
    (comp.lang.fortran)
  • Re: How do you store a stoopid array in the stoopid ViewState?
    ... Unfortunately .NET arrays, even array of value types, are ... The only thing stored on the stack is a reference to the ... > instead of dynamically from the heap. ... > other than to allocate array-space from the heap. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ALLOCATABLE arrays
    ... > If try to create a very large array on the stack and you do not have enough ... > Allocating on the heap gives you access to a hell of a lot more memory (well ... Allocatable arrays are allocated on the heap. ... Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE arrays
    ... || If try to create a very large array on the stack and you do not have enough ... || Allocating on the heap gives you access to a hell of a lot more memory (well ... and "heap" (and there probably are/were some computers which don't/didn't ... | Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)
  • Re: Fortran memory allocation (stack/heap) issues
    ... > rather than Fortran, ... dynamic allocation, and relatively little stack allocation. ... value return and arrays by reference. ...
    (comp.lang.fortran)