comp.lang.ada
 help / color / mirror / Atom feed
From: june.cs.washington.edu!mfeldman@beaver.cs.washington.edu  (Mike Feldman)
Subject: Re: Help with VAX/VMS Ada
Date: 14 Aug 91 04:54:27 GMT	[thread overview]
Message-ID: <1991Aug14.045427.19520@beaver.cs.washington.edu> (raw)

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)
-------------------------------------------------------------------------------

             reply	other threads:[~1991-08-14  4:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-08-14  4:54 Mike Feldman [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-08-12 19:39 Help with VAX/VMS Ada cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!bu.edu!inmet!stt
1991-08-05 19:24 James Burnell, WVU Comp/Ele Engr
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox