home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / fortran / 5133 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.3 KB  |  59 lines

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