From: Robert A Duff <bobduff@TheWorld.com>
Subject: Re: Introductory Presentations, especially aimed at C++ programmers!
Date: Tue, 13 Dec 2016 16:15:54 -0500
Date: 2016-12-13T16:15:54-05:00 [thread overview]
Message-ID: <wcctwa7msxh.fsf@TheWorld.com> (raw)
In-Reply-To: o2npd6$a9a$1@dont-email.me
"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> On 12/12/2016 05:53 PM, Randy Brukardt wrote:
>>
>> A Get_Line like the above
>> generally requires some sort of incremental allocation (a buffer is
>> allocated, if its not big enough a bigger one is allocated, the first one is
>> copied into it, and then we repeat until a <LF> appears),
>
> As the person who created the Get_Line function, I can assure that's not
> how most versions are implemented.
That's how it's done in GNAT. How is it done in "most versions"?
From a-textio.adb:
function Get_Line (File : File_Type) return String is
function Get_Rest (S : String) return String;
-- This is a recursive function that reads the rest of the line and
-- returns it. S is the part read so far.
--------------
-- Get_Rest --
--------------
function Get_Rest (S : String) return String is
-- The first time we allocate a buffer of size 500. Each following
-- time we allocate a buffer the same size as what we have read so
-- far. This limits us to a logarithmic number of calls to Get_Rest
-- and also ensures only a linear use of stack space.
Buffer : String (1 .. Integer'Max (500, S'Length));
Last : Natural;
begin
Get_Line (File, Buffer, Last);
declare
R : constant String := S & Buffer (1 .. Last);
begin
if Last < Buffer'Last then
return R;
else
pragma Assert (Last = Buffer'Last);
-- If the String has the same length as the buffer, and there
-- is no end of line, check whether we are at the end of file,
-- in which case we have the full String in the buffer.
if End_Of_File (File) then
return R;
else
return Get_Rest (R);
end if;
end if;
end;
end Get_Rest;
-- Start of processing for Get_Line
begin
return Get_Rest ("");
end Get_Line;
- Bob
next prev parent reply other threads:[~2016-12-13 21:15 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-10 12:24 Introductory Presentations, especially aimed at C++ programmers! John McCabe
2009-07-10 21:49 ` jimmaureenrogers
2009-07-10 23:37 ` wwilson
2009-07-11 0:07 ` jimmaureenrogers
2009-07-12 4:00 ` wwilson
2009-07-11 8:15 ` Stephen Leake
2009-07-15 6:43 ` Jean-Pierre Rosen
2016-12-07 17:06 ` john
2016-12-07 17:44 ` Luke A. Guest
2016-12-07 18:35 ` Jeffrey R. Carter
2016-12-07 23:03 ` Randy Brukardt
2016-12-07 23:47 ` Jeffrey R. Carter
2016-12-08 0:08 ` Paul Rubin
2016-12-09 22:01 ` Randy Brukardt
2016-12-09 22:18 ` Jeffrey R. Carter
2016-12-13 0:53 ` Randy Brukardt
2016-12-13 3:21 ` Jeffrey R. Carter
2016-12-13 21:15 ` Robert A Duff [this message]
2016-12-13 22:05 ` Jeffrey R. Carter
2016-12-13 22:52 ` Robert A Duff
2016-12-14 0:02 ` Jeffrey R. Carter
2016-12-13 23:05 ` Randy Brukardt
2016-12-14 0:13 ` Jeffrey R. Carter
2016-12-14 22:48 ` Randy Brukardt
2016-12-15 0:00 ` Jeffrey R. Carter
2016-12-15 10:46 ` Maciej Sobczak
2016-12-16 7:37 ` Paul Rubin
2016-12-15 20:14 ` Niklas Holsti
2016-12-15 20:27 ` Jeffrey R. Carter
2016-12-15 21:04 ` Niklas Holsti
2016-12-15 21:40 ` Jeffrey R. Carter
2016-12-16 7:41 ` Paul Rubin
2016-12-13 22:50 ` Randy Brukardt
2016-12-14 0:08 ` Jeffrey R. Carter
2016-12-14 1:01 ` Shark8
2016-12-08 8:08 ` Maciej Sobczak
2016-12-08 8:38 ` Dmitry A. Kazakov
2016-12-08 10:25 ` Paul Rubin
2016-12-08 13:39 ` Maciej Sobczak
2016-12-09 1:30 ` Paul Rubin
2016-12-09 8:31 ` J-P. Rosen
2016-12-09 8:58 ` Paul Rubin
2016-12-09 9:18 ` J-P. Rosen
2016-12-09 9:27 ` Paul Rubin
2016-12-09 10:49 ` J-P. Rosen
2016-12-09 19:58 ` Jeffrey R. Carter
2016-12-09 8:35 ` G.B.
2016-12-09 8:57 ` Paul Rubin
2016-12-09 22:15 ` Randy Brukardt
2016-12-09 21:58 ` Randy Brukardt
2016-12-08 8:23 ` Maciej Sobczak
2016-12-08 18:54 ` Adam Jensen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox