comp.lang.ada
 help / color / mirror / Atom feed
* Efficient Stream_IO
@ 2004-04-13  8:38 Lutz Donnerhacke
  2004-04-13 11:12 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Lutz Donnerhacke @ 2004-04-13  8:38 UTC (permalink / raw)


Is there a portable way to implement efficient IO on streams?
Especially String to Stream_Element_Array conversions?

I do have the problem, that my Ada implementation of a netflow collector
requires considerably more CPU cycles than the C implementation. Of course,
I have to profile the code in detail, but I suspect String'Read/Write as
iterated Character'Reads/Writes as a major contribution.

An unportable implementation would be:

-- Don't do this!
procedure Put(Stream : access Root_Stream_Type'Class; s : String) is
  data : Stream_Element_Array(1 .. s'Length);
  pragma Import(Ada, data);
  for data'Address use s'Address;
  pragma Assert(Stream_Element_Array'Component_Size = String'Component_Size);
  pragma Assert(data'Size = s'Size);
begin
  Write(Stream, data);
end Put;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Efficient Stream_IO
  2004-04-13  8:38 Efficient Stream_IO Lutz Donnerhacke
@ 2004-04-13 11:12 ` Stephen Leake
  2004-04-13 11:32   ` Lutz Donnerhacke
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2004-04-13 11:12 UTC (permalink / raw)
  To: comp.lang.ada

Lutz Donnerhacke <lutz@iks-jena.de> writes:

> Is there a portable way to implement efficient IO on streams?

Depends on how wide a range of hardware and OS you mean by "portable".

The Ada language tries hard to be portable to no OS, hardware that has
39 bit "bytes", hardware that has ones-complement integer arithmetic,
etc.

If you restrict "portable" to mean an OS with a TCP stack, and
hardware with 8 bit bytes, things are much simpler. In fact, the code
you wrote is probably portable among that set.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Efficient Stream_IO
  2004-04-13 11:12 ` Stephen Leake
@ 2004-04-13 11:32   ` Lutz Donnerhacke
  2004-04-14 19:54     ` Pascal Obry
  0 siblings, 1 reply; 5+ messages in thread
From: Lutz Donnerhacke @ 2004-04-13 11:32 UTC (permalink / raw)


* Stephen Leake wrote:
> Lutz Donnerhacke <lutz@iks-jena.de> writes:
>> Is there a portable way to implement efficient IO on streams?
>
> Depends on how wide a range of hardware and OS you mean by "portable".

Real world justification of programmer's attitute:
 It has to be run on a single maschine, specified by the programmer and
 configured as the programmer wishes. It will be an ordinary x86 based
 server from the shelf. The server can be used as initial development
 enviroment. For further developments a simiar maschine will exists.

> The Ada language tries hard to be portable to no OS, hardware that has
> 39 bit "bytes", hardware that has ones-complement integer arithmetic,
> etc.

And how will one convert from String to Stream_Element_Array?
Using String'Output to a self defined, trivial Memory_Stream?

I know the benefits of this approach very well. Instead of mapping a type to
Storage_Element_Array or Stream_Element_Array, the 'Read and 'Write
attributes vanish any alignment and representation problem. That's great and
slow.

> If you restrict "portable" to mean an OS with a TCP stack, and hardware
> with 8 bit bytes, things are much simpler. In fact, the code you wrote is
> probably portable among that set.

Thank you.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Efficient Stream_IO
  2004-04-13 11:32   ` Lutz Donnerhacke
@ 2004-04-14 19:54     ` Pascal Obry
  2004-04-15  8:13       ` Martin Dowie
  0 siblings, 1 reply; 5+ messages in thread
From: Pascal Obry @ 2004-04-14 19:54 UTC (permalink / raw)



Lutz Donnerhacke <lutz@iks-jena.de> writes:

> And how will one convert from String to Stream_Element_Array?

With a loop if Stream_Element'Size /= Character'Size and with a simple
Unchecked_Conversion otherwise. The second solution is very fast and will
work in 99,9% (100%???) of the cases.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Efficient Stream_IO
  2004-04-14 19:54     ` Pascal Obry
@ 2004-04-15  8:13       ` Martin Dowie
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Dowie @ 2004-04-15  8:13 UTC (permalink / raw)


Pascal Obry <pascal@obry.org> wrote in message news:<uhdvmgwt4.fsf@obry.org>...
> Lutz Donnerhacke <lutz@iks-jena.de> writes:
> 
> > And how will one convert from String to Stream_Element_Array?
> 
> With a loop if Stream_Element'Size /= Character'Size and with a simple
> Unchecked_Conversion otherwise. The second solution is very fast and will
> work in 99,9% (100%???) of the cases.

You don't even need a loop if one is a multiple of the other, which
is, I guess, the most likely scenario.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-04-15  8:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-13  8:38 Efficient Stream_IO Lutz Donnerhacke
2004-04-13 11:12 ` Stephen Leake
2004-04-13 11:32   ` Lutz Donnerhacke
2004-04-14 19:54     ` Pascal Obry
2004-04-15  8:13       ` Martin Dowie

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