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: <7q3ghu$cqv@hobbes.crc.com>#1/1 X-Deja-AN: 517674525 References: <37C46FD4.A42CC1A1@res.raytheon.com> <7q1tff$1n9$1@cnn.Princeton.EDU> <37C54509.17E067C1@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:37C54509.17E067C1@res.raytheon.com... > Martin, > Thanx for the info. My unbound string never goes out of scope until I > terminate my program (which is why I "thought" needed to deallocate it > myself). If all I have to do to reclaim the memory is to create a new > string using the same variable, then this takes care of all my > problems. Just to make sure I understand this correctly: > > my_string : ada.strings.unbounded_string; > begin > > -- grab approx 1024 bytes of memory > my_string := new ada.strings.unbounded_string.To_Unbound_String(1024); > > -- give back the 1024 bytes and grab 2048 new memory bytes > my_string := new ada.strings.unbounded_string.To_Unbound_String(2048); > > end > > Is this correct. I know am being simplistic with the actually memory > bytes allocated. But do I have the theory correct? > It's even simpler. One doesn't need to allocate any particular size. One can just keep appending, as necessary. See the following example. After use, assigning the null_unbounded_string deallocates the memory. Then, when desired, begin appending again. with Ada.Text_IO; with Ada.Strings.Unbounded; procedure Demo_Unbounded_Strings is My_String : Ada.Strings.Unbounded.Unbounded_String; begin Ada.Strings.Unbounded.append (Source => My_String, New_Item => "Now is the time"); Ada.Strings.Unbounded.append (Source => My_String, New_Item => " for all good men"); Ada.Strings.Unbounded.append (Source => My_String, New_Item => " to come to the aid of their country."); Ada.Text_Io.Put_Line (Ada.Strings.Unbounded.To_String (My_String)); My_String := Ada.Strings.Unbounded.Null_Unbounded_String; end Demo_Unbounded_Strings; ---------------------------------------------------