From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,1ef3b84ca62fad7b X-Google-Attributes: gidfee84,public X-Google-Thread: 1094ba,1ef3b84ca62fad7b X-Google-Attributes: gid1094ba,public From: nmm1@cus.cam.ac.uk (Nick Maclaren) Subject: Re: fortran error? Date: 1998/03/20 Message-ID: <6etr5i$1p2$1@lyra.csx.cam.ac.uk>#1/1 X-Deja-AN: 335934002 Sender: nmm1@taurus.cus.cam.ac.uk (Nick Maclaren) References: <3507A4A5.F8A7DDC2@matd.tu-graz.ac.at> <6ejfii$kbd@usenet.pa.dec.com> <350E95A7.41C6@still3.chem.columbia.edu> <350EDA13.2781@still3.chem.columbia.edu> <351181DB.2781@still3.chem.columbia.edu> Organization: University of Cambridge, England Newsgroups: comp.lang.fortran,comp.unix.osf.osf1 In article , Craig Burley 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