From: Jeffrey Carter <spam@spam.com>
Subject: Re: Random Input-Size and recognizing ENTER-press
Date: Sun, 19 Dec 2004 16:01:26 GMT
Date: 2004-12-19T16:01:26+00:00 [thread overview]
Message-ID: <qBhxd.4359$RH4.2409@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <mailman.203.1103467874.10401.comp.lang.ada@ada-france.org>
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
next prev parent reply other threads:[~2004-12-19 16:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-19 8:44 Random Input-Size and recognizing ENTER-press xadian
2004-12-19 14:50 ` Marius Amado Alves
2004-12-19 16:01 ` Jeffrey Carter [this message]
2004-12-19 16:03 ` Pascal Obry
2004-12-19 23:47 ` Jeffrey Carter
2004-12-20 14:36 ` Steve
2004-12-20 23:45 ` Jeffrey Carter
2004-12-19 15:52 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox