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: Ted Dennison Subject: Re: Efficient io of arbitrary binary data. Date: 1996/09/17 Message-ID: <323ECE8F.FF6D5DF@escmail.orl.mmc.com>#1/1 X-Deja-AN: 181288401 references: <3239B3B2.1AE4@cray.com> <1996Sep14.112929.1@eisner> content-type: text/plain; charset=us-ascii organization: Lockheed Martin Information Systems mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4m) Date: 1996-09-17T00:00:00+00:00 List-Id: Brian Hanson wrote: > > Brian said > > "> 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." > > Robert Dewar writes: > Well seeing as you have neither slices nor references to slices in C, > it is hardly possible that this limitation is a significant one! DOn't > assume that because you are writing in Ada, you *have* to use all its > features! > > C may not have slices but since a pointer to a char can be considered an > a array, I have the equivalent to a slice by carrying around the length > seperately. I can use memcmp and memcpy to compare and move this block > of data. I would expect that most compilers turn these library calls > into inline code. The Ada equivalent to THAT would be passing around access types, and using UNCHECKED_CONVERSION to hose the source object types into other access types (assuming a typical implementation of access types - check your appendix F). This is, of course, to be avioded. A slightly better method is to declare a "buffer" type which is an array of byte (or integer, whatever's convienent)-sized objects. Eventually you will probably copy data out of your reciept buffer for client use. At THAT point, do the UNCHECKED_CONVERSION. It won't be any extra code, if you are already copying anyway. -- T.E.D. | Work - mailto:dennison@escmail.orl.mmc.com | | Home - mailto:dennison@iag.net | | URL - http://www.iag.net/~dennison |