comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Introductory Presentations, especially aimed at C++ programmers!
Date: Mon, 12 Dec 2016 18:53:52 -0600
Date: 2016-12-12T18:53:52-06:00	[thread overview]
Message-ID: <o2ngr0$6v9$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: o2fagv$n4s$1@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:o2fagv$n4s$1@dont-email.me...
> On 12/09/2016 03:01 PM, Randy Brukardt wrote:
>> "Paul Rubin" <no.email@nospam.invalid> 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 <LF> 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.



  reply	other threads:[~2016-12-13  0:53 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 [this message]
2016-12-13  3:21                   ` Jeffrey R. Carter
2016-12-13 21:15                     ` Robert A Duff
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