From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Subject: Re: fortran error?
Date: 1998/03/20 [thread overview]
Message-ID: <6etr5i$1p2$1@lyra.csx.cam.ac.uk> (raw)
In-Reply-To: y6n2emoxa6.fsf@tweedledumb.cygnus.com
In article <y6n2emoxa6.fsf@tweedledumb.cygnus.com>, Craig Burley <burley@tweedledumb.cygnus.com> writes:
|>
|> Yes, well, it occurred to me later that the history of this
|> area in Fortran probably includes the fact that, indeed, for
|> "classic Fortran", stack overflow was rarely a problem, and
|> that the introduction of automatic arrays was the *single*
|> biggest reason why it might become one.
Yes, that is so. However, for amusement only, people should note
that at least one Fortran II compiler had automatic arrays :-)
The reason that stack overflow is such a problem is because many
systems have assumed the model that it is used only for small
objects, and that other forms of allocation will be used for large
ones. On systems that do NOT make that assumption, there isn't a
problem until you run out of memory entirely.
|> Similarly, heap overflow was rarely a problem for "classic
|> Fortran". Even if the underlying run-time libraries (provided
|> with the compiler) used heap (or stack) storage, the demands
|> of "classic Fortran" applications were probably such that these
|> wouldn't contribute noticably to exhausting these particular
|> resources.
Yes, but remember that Fortran 90 introduced not one but TWO "heap"
concepts. The Unix/C term implies a (more-or-less static) area of
space used for the dynamic allocation of variable sized objects
(i.e. malloc and conspirators). But Fortran 90 also implies a
requirement for this area to be garbage collected (i.e. the Algol 68
use of the term "heap") - and, as with almost all similar languages,
neither requires it nor specifies any properties of the garbage
collector.
I argued this heatedly with some people on X3J3, as I did previously
with some Algol68, Lisp etc. people, and got nowhere. The point is
that you absolutely cannot write portable, robust code if you have
to rely on a garbage collector that may not exist at all or may have
unsuitable properties. And using ALLOCATE for large numbers of short
lifetime objects implies some form of space recovery.
So it would NOT improve matters simply to have large or variable
arrays put on the "heap" - what is critical is to have them put in a
data area that is managed either as a dynamic stack, or as one of
semantic supersets of a dynamic stack. Algol 60 and 68 (and other
languages) proved that dynamic stacks can be implemented efficiently
and easily in several ways.
|> That is, stick to "classic Fortran plus ALLOCATE" or similar, and
|> catching out-of-memory still makes sense the way its done now.
Unfortunately, no it doesn't, for the above reason. You are asking
for trouble simply using ALLOCATE instead of stack allocation as a
way of getting a dynamic stack. It will often work, but you will
then make a minor change or move to a new system, and the memory
will fragment unusably and your program will not run at all.
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
next prev parent reply other threads:[~1998-03-20 5:00 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-03-12 5:00 fortran error? Armin Leuprecht
1998-03-12 5:00 ` robin
1998-03-16 5:00 ` Steve Lionel
1998-03-17 5:00 ` Peter Shenkin
1998-03-17 5:00 ` Craig Burley
1998-03-17 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Craig Burley
1998-03-19 5:00 ` Peter Shenkin
1998-03-19 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Craig Burley
1998-03-23 5:00 ` Peter Shenkin
1998-03-24 5:00 ` Craig Burley
1998-03-24 5:00 ` Nick Maclaren
1998-03-23 5:00 ` Summary (I hope) failure of automatic allocation; was, " Peter Shenkin
1998-03-24 5:00 ` Craig Burley
1998-03-20 5:00 ` Nick Maclaren
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Richard Maine
1998-03-20 5:00 ` Nick Maclaren [this message]
1998-03-20 5:00 ` Dick Hendrickson
1998-03-20 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-23 5:00 ` Craig Burley
1998-03-20 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Toon Moene
1998-03-18 5:00 ` Jeff Drummond
1998-03-19 5:00 ` Peter Shenkin
1998-03-18 5:00 ` Steve Lionel
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox