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: Mon, 12 Dec 2016 18:53:52 -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 1481590432 7145 24.196.82.226 (13 Dec 2016 00:53:52 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 13 Dec 2016 00:53:52 +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:32770 Date: 2016-12-12T18:53:52-06:00 List-Id: "Jeffrey R. Carter" wrote in message news:o2fagv$n4s$1@dont-email.me... > On 12/09/2016 03:01 PM, Randy Brukardt wrote: >> "Paul Rubin" wrote in message >> news:877f7b5llo.fsf@nightsong.com... >>>> exponentially better than being prevented from overflowing a buffer is >>>> being able to figure out how to do >>>> declare >>>> B : Buffer (1 .. Just_The_Right_Size); >>> >>> Alternatively the buffer could be dynamically sized according to the >>> data. That's not in the Ada spirit because of the possible OOM and >>> memory allocation latency getting in the way of embedded realtime >>> applications, but for a workstation app it's perfectly workable. >>> Horses for courses. >> >> That's one possible way to use the API in question, since there's no way >> to >> find out beforehand how much data you'll need. (You could ask for the >> size >> ahead of time, but of course that's a potential race condition so it >> doesn't >> really help.) > > I was including in being able to do > > declare > B : Buffer (1 .. Just_The_Right_Size); > > such things as > > declare > S : String := Get_Line; > > and there's usually a way to do that even when you don't know beforehand > how big the result will be. After all, the Get_Line function doesn't know > beforehand how long a String it will return. I don't how the API in > question works, so I can't say for sure if there's a way to do this for > it, but there usually is. For reading from a device (like a keyboard), it's impossible to know ahead of time what is going to be read (without forcing some sort of pause into the program which is usually not wanted). 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 appears), and thus you need to avoid such Get_Lines for things where performance might matter (like reading from a file). [If you can figure out what kind of entity a handle accesses, then perhaps you could use a different implementation for a file vs. a device; as always, how complicated do you want to make your I/O libraries??] Randy.