comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: problems with interfacing c
Date: Fri, 21 Jan 2011 00:03:22 +0100
Date: 2011-01-21T00:03:22+01:00	[thread overview]
Message-ID: <10wpqz6h1md5o.1gxwql45phwmt.dlg@40tude.net> (raw)
In-Reply-To: op.vpml29i2ule2fv@garhos

On Thu, 20 Jan 2011 22:31:47 +0100, Yannick Duch�ne (Hibou57) wrote:

> Le Thu, 20 Jan 2011 21:56:52 +0100, Dmitry A. Kazakov  
> <mailbox@dmitry-kazakov.de> a �crit:
> 
>> On Thu, 20 Jan 2011 12:21:08 -0800 (PST), Stoik wrote:
>>
>>> I need your help in finding a proper Ada code to simulate the behaviour  
>>> of the
>>> following lines in C:
>>> char *bufor = (char*)malloc(100000);
>>> fread(bufor, 1, 100000, stdin);
>>
>> That depends on what are going to achieve. Translating the above  
>> literally:
>>
>> [ with Ada.Text_IO.Text_Streams;
>>   use Ada.Text_IO, Ada.Text_IO.Text_Streams; ]
>>
>>
>>    Buffer : String (1..100_000);
>> begin
>>    String'Read (Stream (Standard_Input), Buffer);
>>
>> [ Which certainly nobody would do, but you didn't provide any information
>> about the actual problem. ]
> 
> Some body do, for some kind of raw IO. Just that this may be more oftenly  
> something like
>     Character'Read (Standard_Input), C);

That the point, when reading characters that suggests some character stream
oriented protocol. Dealing with such protocols one would never read 100K in
one chunk. Because if the client does something wrong that would deadlock
forever.

> in a loop instead (always wondered if there is a more efficient way, I do  
> not know one), because most of time the buffer size may vary in 1..n (I  
> suppose it may vary for the OP matter too).

The best way is full duplex I/O. You should always be prepared to read at
least one character, so that the client is never blocked when it writes
anything out.

P.S. It would be nice if Ada standard library provided asynchronous
in-place I/O facilities (like overlapped I/O). Ada's protected objects are
perfect candidates for this abstraction (as it was done with interrupts
handlers). But I doubt that would ever happen.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-01-20 23:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-20 20:21 problems with interfacing c Stoik
2011-01-20 20:56 ` Dmitry A. Kazakov
2011-01-20 21:31   ` Yannick Duchêne (Hibou57)
2011-01-20 23:03     ` Dmitry A. Kazakov [this message]
2011-01-21  0:46       ` Yannick Duchêne (Hibou57)
2011-01-21  9:33         ` Dmitry A. Kazakov
2011-01-28  0:39   ` Stoik
2011-01-28  5:24     ` Yannick Duchêne (Hibou57)
2011-01-28  9:41     ` Ludovic Brenta
2011-01-28  9:44     ` Dmitry A. Kazakov
2011-01-31 21:46       ` Stoik
2011-01-31 23:06         ` Edward Fish
2011-02-01  8:48         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox