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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b5cd7bf26d091c6f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!32g2000vbe.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Reading the while standard input into a String Date: Mon, 6 Jun 2011 08:18:44 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1e5e764d-eb7b-4804-8119-b535ddbe5e7e@32g2000vbe.googlegroups.com> References: NNTP-Posting-Host: 83.3.40.82 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1307373524 6716 127.0.0.1 (6 Jun 2011 15:18:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 6 Jun 2011 15:18:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 32g2000vbe.googlegroups.com; posting-host=83.3.40.82; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19641 Date: 2011-06-06T08:18:44-07:00 List-Id: On Jun 6, 10:33=A0am, Ludovic Brenta wrote: > Personally I think this is a fundamentally bad idea. =A0Consider: > > $ my_program < /dev/random If the program has the concept of reading its input, then apparently it is supposed to run in a bigger context (a system) which we know nothing about. If that system's specification puts upper bounds on what is fed on each component's input, then yes, this is a perfectly good idea and your example just does not represent any intended use case. What I'm up to is that reliability guarantees might come from different sources and scopes and your "problem" might have been already solved. This is not necessarily just another version of cat or grep. > Do you consider it acceptable to use all memory I find it acceptable to read all input before processing it, if I know the other programs that will produce the input data for this program. > I'd rather process the input one fixed-length chunk at a time This is a can of warms - how big should be that chunk? :-) > Note that reading one character at a time from a stream is quite fast > since streams normally use the operating system's buffered IO. Adding > a second layer of buffering inside your program is probably counter- > productive. Or not. System calls are relatively expensive - typically much more expensive than copying data around. For this reason wisely used additional buffers can improve performance of I/O operations. -- Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com