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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ddba2f4eebde1467 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-31 17:01:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail Message-ID: <3F29ADD6.4090400@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Elegant 'realloc'? References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 66.31.71.243 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc01 1059696113 66.31.71.243 (Fri, 01 Aug 2003 00:01:53 GMT) NNTP-Posting-Date: Fri, 01 Aug 2003 00:01:53 GMT Organization: Comcast Online Date: Fri, 01 Aug 2003 00:01:54 GMT Xref: archiver1.google.com comp.lang.ada:41116 Date: 2003-08-01T00:01:54+00:00 List-Id: Lutz Donnerhacke wrote: > When dealing with dynamically allocated variable length arrays, the > allocated space might change. Is there a common idiom to simulate an > 'realloc' (especially shrinking) other than, allocate, copy, free? > > declare > procedure Free is new Unchecked_Deallocation(T_Array, T_Array_Access); > oldp : constant T_Array_Access := current.field; > begin > current.field := new T_Array'(oldp(oldp'First .. current.last)); > Free(oldp); > end; I would just write: declare Current: T_Array(1..Whatever); begin -- process Current end; The array Current gets put on the stack. If you really need the array to be extensible, containing the old value, you can either use recursion, the heap, or Ada.Strings.Unbounded. ;-) -- "As far as I'm concerned, war always means failure." -- Jacques Chirac, President of France "As far as France is concerned, you're right." -- Rush Limbaugh