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,8ab6ed0f71c479cd,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!a12g2000yqm.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: API design problem - buffer scatter I/O Date: Sat, 22 Nov 2008 08:05:31 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 85.3.202.3 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1227369931 2524 127.0.0.1 (22 Nov 2008 16:05:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 22 Nov 2008 16:05:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a12g2000yqm.googlegroups.com; posting-host=85.3.202.3; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2749 Date: 2008-11-22T08:05:31-08:00 List-Id: 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 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