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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7402728c011ea87a X-Google-Attributes: gid103376,public From: kilgallen@eisner.decus.org (Larry Kilgallen) Subject: Re: Efficient io of arbitrary binary data. Date: 1996/09/14 Message-ID: <1996Sep14.112929.1@eisner>#1/1 X-Deja-AN: 180590216 x-nntp-posting-host: eisner.decus.org references: <3239B3B2.1AE4@cray.com> x-nntp-posting-user: KILGALLEN x-trace: 842714977/26592 organization: LJK Software newsgroups: comp.lang.ada Date: 1996-09-14T00:00:00+00:00 List-Id: In article <3239B3B2.1AE4@cray.com>, "Brian R. Hanson" writes: > I recently had to replace a merge/sort program written in terible > fortran with a new implimentation written in c. > > The data being sorted is variable length binary records. The > sort reads as many records as fit into some large buffer sorts them > and writes the sorted data to a file in large blocks. THe blocks > are generated so that no record spans a block and the size of the block > is chosen to be efficiently read and written by the os. Given that many constraints, you are bound to do some individualized fiddling, which is the basic operational mode for C. Such activities are possible in Ada, but not using the higher level constructs which make the language popular with its adherents. > I considering how this program could be written in Ada (part of > an attempt to become Ada literate in an Ada hostile environment) > I a puzzled. The approaches which Ada seems to allow all require > much more copying of data as I am not allowed to return a reference > to a slice of an array I can only return the slice itself. Given that your input is performed in some os-specific fashion anyway (your approach seems to indicate you would not want extra os buffering), you could return an access to the input buffer (array) and indices for the start and ending bytes of a particular record. Copy the data when you are ready to ship the record out. Given a high-quality optimizing compiler, a tight loop to move the bytes should not be any less efficient than having it done by a run-time-library. Larry Kilgallen