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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e30b6046584172fe X-Google-Attributes: gid103376,public From: Niklas Holsti Subject: Re: Help: Dynamic-size arrays using record discriminant. Date: 1998/10/11 Message-ID: <36208A62.80E2640B@icon.fi>#1/1 X-Deja-AN: 399903174 Content-Transfer-Encoding: 7bit References: <361E3D0C.41AAC13B@classnet.co.il> Content-Type: text/plain; charset=us-ascii Organization: Space Systems Finland Ltd Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-11T00:00:00+00:00 List-Id: Alon Matas wrote: > > -- I have this problem: > -- There is a record with a discriminant (and a default value to the > -- discriminant). The record contains a constrained array, and the range > -- of the array depends on the discriminant. For example: > > procedure PROBLEM is > > type ARRAY_TYPE is array (INTEGER range <>) of NATURAL; > type RECORD_TYPE (SIZE: INTEGER:= 5) is > record > VECTOR: ARRAY_TYPE (1..SIZE); > end record; > > -- Now, I have a variable with the record type: > REC: RECORD_TYPE; > TEMP: RECORD_TYPE; -- This variable will be explained later. > > -- The question is how do I change the array size (i.e, the discriminant > > -- value) WITHOUT loosing its current content. [text snipped] > Of course, I can do something like this: > > REC:= (SIZE => 6, VECTOR => (others => 0)); You can do REC := (SIZE => 6, VECTOR => REC.VECTOR & (6 => 0)); However, the compiler is likely to generate a temporary and copy VECTOR contents back and forth. If this is performance- critical, you should perhaps consider other data structures where existing VECTOR data remain in place. For example, the SIZE could be an ordinary component, instead of a discriminant. You must then constrain the VECTOR component to some assumed maximum size. You should anyway constrain the SIZE discriminant, since some compilers will allocate RECORD_TYPE memory for the maximum possible SIZE value (integer'last in your code). - Niklas