home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: Block Data is evil
- Message-ID: <1993Jan22.183106.15813@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1993Jan20.143408@roper.mc.ti.com> <1993Jan21.074755.14939@arcetri.astro.it>
- Date: Fri, 22 Jan 1993 18:31:06 GMT
- Lines: 47
-
- In article <1993Jan21.074755.14939@arcetri.astro.it>, lfini@sisifo (Luca Fini) writes:
- |> W. Donald Rolph (a722756@roper.mc.ti.com) wrote:
- |> :
- |> : Equivalence is in some cases the only possiblity for run time memory allocation
- |> :
- |>
- |> Equivalence is *not* a run rime memory allocation, you simply call the
- |> same memory area with different names (and possibly use it as different
- |> data types).
-
- Yes, and that permits you to do run-time management of a statically
- allocated "maximum" space. You figure out what the maximum memory
- you ever need is and you statically allocate that much:
-
- PARAMETER (MAXMEM=1000000)
- COMMON /MEMORY/ MEM(MAXMEM)
-
- This reserves one million integer sized words. Now, you can write
- a MALLOC routine which returns avalable space from within this array
- in the form of an index (you actually have two mallocs, one for
- integers and reals, the other for complex and doubles - since the
- indices must be scaled differently). To use:
-
- PARAMETER (MAXMEM=1000000)
- COMMON /MEMORY/ MEM(MAXMEM)
- ...
- REAL RMEM(1) !declare length one, you use more
- EQUIVALENCE (MEM(1),RMEM(1))
- ...
- RA = MALLOC(100) !set RA to index of a 100-long block
- ...
- DO 10 I=0,99
- RMEM(RA+I) = ...
- ...
- 10 CONTINUE
-
- You could even write a preprocessor which allowed you to write RA[I]
- and the processor would automatically turn it into RMEM(RA+I). (Note
- the similarity to the C rule of turning a[i] into *(a+i) - the only
- difference is that C calls the common memory area `*' instead of `MEM'.)
- To use MEM as a double or complex, you simply declare DMEM and CMEM
- arrays and equivalence them to MEM as well. You should then use DALLOC
- to reserve space and your `pointers' should be named beginning with D
- or C so the preprocessor can figure out which equivalenced array to use.
-
- --
- J. Giles
-