Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!hub.ucsb.edu!ucsbuxa!3003jalp From: 3003jalp@ucsbuxa.ucsb.edu (Applied Magnetics) Newsgroups: comp.lang.fortran Subject: Re: Dimensioning arrays at run-time, best way? Message-ID: <6306@hub.ucsb.edu> Date: 18 Sep 90 21:32:24 GMT References: <614@keele.keele.ac.uk> Sender: news@hub.ucsb.edu Lines: 27 (Mail bounced) In article <614@keele.keele.ac.uk> phd11@.uk.ac.keele (Zipzoid) writes: >... what is the best way of dimensioning an array whose maximum >memory requirement (size) would be read in at run-time? You can't do it without violating the Fortran standard in some way. The best alternative is to have a very simple main program read the size, allocate the array in some machine-dependent way and pass the array and its size to a normal Fortran subroutine that does the real work. If you port the code, your fallback position is to lobotomize the main program: declare a large static array, read the size, check that the array is big enough, then call the subroutine. Not so good, but perhaps better than nothing: you can compile the subroutine and its dependents once and for all. To change the size, you recompile only the main and re-link it with the rest. My earlier post, `Fun with pointers', was prompted by my own attempts to do better. Using a stratagem to mimick pointer variables, I wrote a Fortran copy of malloc() and free() from the appendix in Kernighan and Ritchie, with an assembler assist to replace the sbrk system call. My code is NOT portable. The consensus is that it would break on a semgented memory architecture. --P. Asselin, AMC