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,a5bde054ac3effc5 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Unbounded string deallocation Date: 1999/08/26 Message-ID: <7q38et$aba@hobbes.crc.com>#1/1 X-Deja-AN: 517674523 References: <37C46FD4.A42CC1A1@res.raytheon.com> Organization: Coleman Research Corporation X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Newsgroups: comp.lang.ada Date: 1999-08-26T00:00:00+00:00 List-Id: Andy Askey wrote in message news:37C46FD4.A42CC1A1@res.raytheon.com... > I am looking into using Ada.Strings.Unbounded for dynamically creating > temporary storage of character arrays. When I am finished processing > the string, I want to deallocate it. I found a "Free" routine in the > spec but this uses a pointer to STRING and not UNBOUNDED_STRING. > > From the Apex ada.strings.unbounded.1.ada => > > type Unbounded_String is private; > type String_Access is access all String; > procedure Free (X : in out String_Access); > > Can anyone help me out with the deallocation? Anyone have a better idea > for dynamically allocating and deallocating memory for a small to medium > size byte array? > Not only does the LRM guarantee that unbounded strings are automatically deallocated when they go out of scope (as Martin Carlisle has pointed out), the implementation of Unbounded strings (at least in the GNAT compiler) provides a good example of how to provide this kind of behavior for any type. The use of the Ada95 controlled type mechanism makes memory management much more straightforward. Section 7.6 of the LRM discusses controlled types in detail.