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-Thread: 103376,966831d952eefbb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Random Input-Size and recognizing ENTER-press References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 19 Dec 2004 23:47:23 GMT NNTP-Posting-Host: 63.190.72.169 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1103500043 63.190.72.169 (Sun, 19 Dec 2004 15:47:23 PST) NNTP-Posting-Date: Sun, 19 Dec 2004 15:47:23 PST Xref: g2news1.google.com comp.lang.ada:7087 Date: 2004-12-19T23:47:23+00:00 List-Id: Pascal Obry wrote: > That's not right. There is a buffer that is allocated when there is no more > space into an Unbounded_String. So there is far less that N allocation when > adding N characters into an Unbounded_String. Here's what I have: Null_String : aliased String := ""; function To_Unbounded (S : String) return Unbounded_String renames To_Unbounded_String; type Unbounded_String is new AF.Controlled with record Reference : String_Access := Null_String'Access; end record; procedure Append (Source : in out Unbounded_String; New_Item : in Character) is S_Length : constant Integer := Source.Reference.all'Length; Length : constant Integer := S_Length + 1; Tmp : String_Access; begin Tmp := new String (1 .. Length); Tmp (1 .. S_Length) := Source.Reference.all; Tmp (S_Length + 1) := New_Item; Free (Source.Reference); Source.Reference := Tmp; end Append; Starting with a null string, that certainly looks like N allocations. -- Jeff Carter "I was hobbling along, minding my own business, all of a sudden, up he comes, cures me! One minute I'm a leper with a trade, next minute my livelihood's gone! Not so much as a 'by your leave!' You're cured, mate. Bloody do-gooder!" Monty Python's Life of Brian 76