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,FREEMAIL_FROM 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!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 20 Dec 2004 08:36:19 -0600 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Random Input-Size and recognizing ENTER-press Date: Mon, 20 Dec 2004 06:36:22 -0800 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response Message-ID: NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-dBCFx8fY7J0LwFopZ26mUXiqTe5OAUBPTSIfhMn5nW3xm1hg8wFf1j9cCOu04nVf462P3KKopXbbmq6!7wRL+CCdl+Wy4Wsu6wBBXRFuYR7p0Omfk0hXU0I9YyD0dJWKoACNWUT0rBTM X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.22 Xref: g2news1.google.com comp.lang.ada:7093 Date: 2004-12-20T06:36:22-08:00 List-Id: IMHO it's silly to worry about the number of allocations an deallocations when you're talking about keeping up with someone typing at a keyboard (especially at todays processor speeds). Steve (The Duck) "Jeffrey Carter" wrote in message news:qBhxd.4359$RH4.2409@newsread1.news.pas.earthlink.net... > Marius Amado Alves wrote: > >> function Get_String return String is >> U : Unbounded_String; >> begin >> loop >> Get_Immediate (C); >> exit when C = CR; >> Append (U, C); >> end loop; >> return To_String (U); >> end; > > You might want to take a look at the source for Ada.Strings.Unbounded from > GNAT before advocating an approach such as this. Every addition of a > Character allocates a new String, copies the old String + new Character > into the new String, and deallocates the old String. For a string of N > Characters, that's N allocations and deallocations. Using Get_Line to > obtain the Characters can improve that to N / Buffer'Length + 1. > > It's not clear that the OP really requires Get_Immediate; the only > requirement stated is the need to read an arbitrary-length String. The > discussion of recognizing when the Enter key is pressed is part of a > proposed solution, not the problem. > > -- > Jeff Carter > "C++: The power, elegance and simplicity of a hand grenade." > Ole-Hjalmar Kristensen > 90