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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,386228a37afe967f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-21 01:49:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.r-kom.de!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Computer Language Shootout Date: Mon, 21 Jul 2003 10:53:46 +0200 Message-ID: References: <1ec946d1.0307150715.4ba69f85@posting.google.com> <3F149243.80304@attbi.com> <3F15930C.2070907@attbi.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1058777382 14828671 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:40537 Date: 2003-07-21T10:53:46+02:00 List-Id: On 18 Jul 2003 23:22:10 +0200, Pascal Obry wrote: > >Robert A Duff writes: > >> "Jean-Pierre Rosen" writes: >> >> > This one reads a line with no length limit: >> > >> > function Get_Line return String is > [...] >> >> Too bad this was not included in Text_IO itself. It would save >> beginners a lot of trouble. Sigh. > >But this approach can use a lot of stack space and become very slow. >Returning an unconstraint object on the stack has a cost. I don't think that the following, heap-based, version could be much faster: Increment : constant := 500; type String_Ptr is access all String; procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr); procedure Read_Line ( Line : in out String_Ptr; Length : out Natural ) is Size : Natural; begin Get_Line (Line.all, Size); Length := Size; while Size = Line'Last loop declare Old_Line : String_Ptr := Line; begin Line := new String'(Old_Line.all & (1..Increment => ' ')); Free (Old_Line); end; Get_Line (Line (Length + 1..Line'Last), Size); Length := Length + Size; end loop; end Read_Line; used as: Line : String_Ptr := new String'(1..Increment => ' '); Length : Natural; begin is Read_Line (Line, Length); ... Free (Line); exception when others => Free (Line); raise; Though it should remove exponential growth [at cost of nasty pointers]. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de