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: 29 Apr 92 13:55:31 GMT From: psinntp!vitro.com!v7.vitro.com!vaxs09@uunet.uu.net Subject: Re: Oh, no! Ada-strings... Message-ID: <1992Apr29.085531.159@v7.vitro.com> List-Id: >toron@CCUCVX.UNICAN.ES (Borja TORON ANTONS) writes: > The solution is to use 'variable strings' as follows: > > Package Var_string is > type vstring(len: natural:=200) is record > str : STRING (1..len); > end record; *heavy sigh* Most of the time, this won't work. You are declaring an unconstrained type that can take an amount of storage between 1 and integer'last (approximately). The compiler has two reasonable choices in dealing with objects of this type. 1. Preallocate the maximum space needed by any object of that type. 2. Allocate the current size for the object. Re-allocate when the space requirement changes. The tradeoff here is one of speed (1 chews less CPU) against space (2 chews less memory). By default, my compiler (VAX Ada) and many others will choose option 1, pre-allocating your "variable" strings. In my case, that's 2 gigabytes of storage for one string. At run time, an attempt to allocate a vstring produces a constraint error. John Briggs vaxs09@v7.vitro.com