From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 14 Aug 91 04:54:27 GMT From: june.cs.washington.edu!mfeldman@beaver.cs.washington.edu (Mike Feldman) Subject: Re: Help with VAX/VMS Ada Message-ID: <1991Aug14.045427.19520@beaver.cs.washington.edu> List-Id: In article <20600114@inmet> stt@inmet.inmet.com writes: > >By providing a default for all discriminants, you are allowing the >declaration of unconstrained instances of Vector. > >E.g., the following would now be legal: > X : Vector; > >In this situation, most Ada compilers will allocate >space sufficient to hold the largest possible value. >In this case, the largest value is truly enormous, >because the range of the discriminants is Integer. [stuff deleted] This is one of the interesting portability "gotchas" in the language. Many compilers (at least the Janus, Meridian, and Alsys families) do NOT allocate the maximum space, preferring to reallocate when the size of the object changes dynamically. Meridian allocates only a pointer block and acquires space as needed; I believe the Janus family does the same. I am not sure of the Alsys policy, but think I heard somewhere that Alsys uses the default as an approximation, then chains in more space as needed (can anyone confirm?). The time/space tradeoff here is interesting to consider. Allocating the maximum space obviates the need to reallocate or acquire space dynamically. Other policies save space at the cost of some time to reallocate. The best approach, as Tucker points out, is to use a subtype of some realistic size for the discriminant. I'm sure the original writer never intended his vectors to have Integer'Last elements, and so ought to have considered what the _realistic_ maximum should be. There's a moral here. The type system can be your friend or your enemy, as this case points out. Using a realistic subtype is better design and also more portable, as it will likely cause something reasonable to be done in every implementation. ------------------------------------------------------------------------------- Michael B. Feldman Visiting Professor 1991-92 Professor Dept. of Comp. Sci. and Engrg. Dept. of Elect. Engrg. and Comp. Sci. University of Washington FR-35 The George Washington University Seattle, WA 98105 Washington, DC 20052 (206) 685-1376 (voice) (202) 994-5253 (voice) (206) 543-2969 (fax) (202) 994-5296 (fax) -------------------------------------------------------------------------------