🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #92

Re: Dynamic arrays in Modula-2?

#92
From: David M. Brumley
Date: Fri, 10 Apr 1992 08:13
45 lines
1930 bytes
In article <11353@mindlink.bc.ca> Changhao_Boh@mindlink.bc.ca (Changhao Boh)
writes:
   DM> How does one express dynamic allocation of single and
   DM> multi-dimensional arrays in Modula-2?  How does one pass a dynamically
   DM> allocated multi-dimensional array as an argument to a procedure?
   DM>
   DM> For example, if a two or three dimensional array of INTEGERs resides in
   DM> file on disk, and the dimensions of the data set are specified at the
   DM> beginning of the file, how can the file be loaded and manipulated
   DM> using a Modula-2 program?
   DM>
   DM> My references on Modula-2 lead me to believe that this elementary
   DM> operation is difficult or impossible to [implement -dmb] elegantly or
   DM> portably in Modula-2.

   Via user defined datatypes, sir, user defined datatypes, user defined
   datatypes.

   You'll have to write your own opaque data sturctures to accomplish what you
   want.

   To begin,

   TYPE
     MultiDimArray   = ARRAY [1..100] [1..100] [A..Z] OF CARDINALS;

     aMultiDimArray  = POINTER TO MultiDimArray;

   VAR
     Array : aMultiDimArray;

   BEGIN
     ALLOCATE(Array, SIZE(Array^));

     (* Do your stuffs... *)

     DEALLOCATE(Array, SIZE(Array^));

   END.


Sorry, I tried to say in the second paragraph above that the dimensions
of the array are not known at compile time.  I assume (for now) that
the number of dimensions is known.  I guess I should have said
"dynamic declaration" instead of "dynamic allocation."
Technical Details
Message-ID: <DMB.92Apr10021330@srl03.usl.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!tulane!rouge!rouge!dmb

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.modula2
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!tulane!rouge!rouge!dmb
From: dmb@srl03.usl.edu (David M. Brumley)
Subject: Re: Dynamic arrays in Modula-2?
Message-ID: <DMB.92Apr10021330@srl03.usl.edu>
Sender: anon@usl.edu (Anonymous NNTP Posting)
Organization: University of Louisiana
Date: Fri, 10 Apr 1992 08:13:30 GMT
Lines: 45