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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Introductory Presentations, especially aimed at C++ programmers! Date: Tue, 13 Dec 2016 17:05:53 -0600 Organization: JSA Research & Innovation Message-ID: References: <1905815374.502825168.454102.laguest-archeia.com@nntp.aioe.org> <877f7b5llo.fsf@nightsong.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1481670354 6137 24.196.82.226 (13 Dec 2016 23:05:54 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 13 Dec 2016 23:05:54 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Response Xref: news.eternal-september.org comp.lang.ada:32798 Date: 2016-12-13T17:05:53-06:00 List-Id: "Jeffrey R. Carter" wrote in message news:o2pr84$fis$1@dont-email.me... ... > return Buffer & Get_Line; This does dynamic allocation of some sort under the covers, and in any case copies the contents of both parts of the string. The version Bob shows is more complicated in order to control the amount of stack space used, and appears to be designed to maximize the use of stack space rather than allocated temporaries for GNAT. That seems like a win for their implementation. In Janus/Ada, both of these formulations would do a heck of a lot of dynamic allocation under the covers (anything dynamically sized is allocated from a storage pool ultimately). [That's what I was thinking of when I said "dynamically allocated".] & of unconstrained strings is VERY expensive, so I would write a routine similar to the one Bob showed, but I'd use slicing rather than & to create the final result. (Given the general nature of Get_Line, and the way it is used, it will be on some program's critical path, so it can never be fast enough.) [I used future tense as this particular Ada 2005 change hasn't yet made it into Janus/Ada.] Conclusion: I don't see any difference between Bob's version and yours in terms of dynamic memory allocation needed. Randy.