From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada Subject: Re: What should this do? Keywords: Variable-length strings constraint exception Message-ID: <3417@sparko.gwu.edu> Date: 29 Jun 91 16:44:27 GMT References: <1991Jun28.193513.14271@afit.af.mil> <1991Jun29.003159.20278@netcom.COM> Sender: news@seas.gwu.edu Reply-To: mfeldman@seas.gwu.edu (Michael Feldman) Organization: The George Washington University, Washington, D.C. List-Id: In article <1991Jun29.003159.20278@netcom.COM> jls@netcom.COM (Jim Showalter) writes: > >No. If you declare S of type Dyn_String without specifying a value >for the Size, what you get is a "mutable record". What this means is >that you can come along later and assign a Dyn_String of any size to >it, and it will work. The reason is that the default size of zero >is NOT a discriminant, and so does not constrain the Data string to >be of any particular size. A nifty compiler could play all sorts of >games with mutable records to make them grow or shrink dynamically. >As it is, a typical compiler simply allocates as much space as COULD >be needed, and lets it go at that. In your example, this means 100 >bytes or so of storage is allocated, regardless of whether you ultimately >assign a two character string to S or a 73 character string to S. Hmmm. This is not quite correct, Jim, regarding space allocation. For example, Meridian allocates only a header block (dope vector, whatever) and acquires space dynamically when needed. TeleSoft allocates the maximum, which means that if the revord were declared as record (length: positive := whatever) stuff: string(1..length) end record; the runtime system would try to acquire positive'last bytes. Big trouble. On the other hand, allocating the maximum means that no reallocation ever has to be done for the life of the object. Moral: use the subtype system to keep the max length to a value that's realistic in your application. I was told once (but can't confirm) that Alsys uses a _linked_ allocation, starting out with a blocksize equal to the default value and getting more blocks as needed. Can anyone confirm this? The point of my writing this is that implementing a powerful structure often involves classical time/space tradeoffs: Meridian will use time to save space (by always reallocating); TeleSoft will use space to save time. Alsys is in between somewhere. The wise designer will understand this and use the best structures for the job, in this case by choosing a range for the discriminant that makes sense. This is one of the portability gotchas in using any powerful structure; the careless designer will probably get burned the worst. BTW: I haven't seen a compiler manual yet that didn't lay out the details of their data structures, just in case you're curious. Mike