comp.lang.ada
 help / color / mirror / Atom feed
* API design problem - buffer scatter I/O
@ 2008-11-22 16:05 Maciej Sobczak
  2008-11-22 16:54 ` sjw
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: Maciej Sobczak @ 2008-11-22 16:05 UTC (permalink / raw)


I have a problem finding the best, from the Ada point of view,
interface for the scatter I/O API.

The idea is that the library is able to read some bytes from somewhere
and put them in the buffers provided by user. The simplest, single-
buffer version of this idea is used in the standard library and in
many others - an example from GNAT.Sockets looks like here:

procedure Receive_Socket
     (Socket : Socket_Type;
      Item   : out Ada.Streams.Stream_Element_Array;
      Last   : out Ada.Streams.Stream_Element_Offset);

In other words, user provides a single array and the library fills it
with data.

The problem is that this is a single, continuous array.
How would you approach the design of API for multi-buffer I/O? Multi-
buffer means that the user can provide many arrays, probably of
different sizes, and the library will fill them from first to last.

The following assumptions are true:
1. The user knows up-front how much data will be read. It will never
be less, so there is no need to give back any Last index, like above.
The user has to only ensure that the sum of buffer lengths is
appropriate for all the data that will be read.
2. Buffers don't need to have the same size.
3. Individual buffers are not necessarily related (they don't have to
be components of common bigger structure like record or array).
4. It really has to be a single operation, so no cheating with
repeated calls for separate buffers to get consecutive fragments.

My initial idea was that the subprogram might have a parameter that is
an array of access values to separate buffers (actual buffers must be
therefore aliased). Are buffer bounds properly handled when only
access to array is given (didn't check that yet, sorry)?

My initial idea:

type Buffer_Ptr is access Ada.Streams.Stream_Element_Array;
type Buffers is array (Positive range <>) of Buffer_Ptr;

procedure Scatter_Input_Data (B : in Buffers);

What is bothering me is <http://en.wikibooks.org/wiki/Ada_Programming/
Types/access> and the discussion on designated vs. nominal subtypes in
the "Fat pointers" paragraph.

Have you seen an existing library that solves this problem is some
reasonable way?
Do you have other ideas or suggestions for how to design such API?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



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

end of thread, other threads:[~2008-11-26 20:39 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-22 16:05 API design problem - buffer scatter I/O Maciej Sobczak
2008-11-22 16:54 ` sjw
2008-11-22 19:43 ` george.priv
2008-11-22 22:16 ` Robert A Duff
2008-11-22 23:34   ` Maciej Sobczak
2008-11-23  0:01     ` Robert A Duff
2008-11-24  8:10       ` Brad Moore
2008-11-24  7:55   ` christoph.grein
2008-11-24 20:03     ` Robert A Duff
2008-11-25  5:59       ` christoph.grein
2008-11-25  8:34         ` Dmitry A. Kazakov
2008-11-25 14:25         ` Robert A Duff
2008-11-25 22:20       ` Randy Brukardt
2008-11-24 21:23     ` Robert A Duff
2008-11-22 23:01 ` Georg Bauhaus
2008-11-23  5:57 ` anon
2008-11-24 17:16 ` tmoran
2008-11-26  8:34   ` Maciej Sobczak
2008-11-26 20:39     ` sjw

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