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: brh@poplar111.cray.com (Brian Hanson) Subject: Re: Efficient io of arbitrary binary data. Date: 1996/09/16 Message-ID: #1/1 X-Deja-AN: 180845732 references: <3239B3B2.1AE4@cray.com> <1996Sep14.153426.1@eisner> organization: Cray Research a division of Silicon Graphics, Inc. newsgroups: comp.lang.ada Date: 1996-09-16T00:00:00+00:00 List-Id: Larry Kilgallen) writes: In article <3239B3B2.1AE4@cray.com>, "Brian R. Hanson" writes: > 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. Presuming the concern is runtime efficiency rather than code inspection efficiency :-), whether you return a slice or a reference to a slice may be immaterial. A compiler with aggressive optimization may generate inline code for your whole "read" function, making the object code for the two methods equivalent. When programming in Ada you have given the compiler more information than programming in C, so it has more opportunity to optimize. Based on your return address, I would presume folks in your shop are big on optimizing compilers. Actually, folks in our shop are big on optimizing c, c++ and fortran compilers. My target platforms - sgi (our new parent) and sun (our workstation of choice prior to acquiring a parent) - use gnat. is it really likely that case compare_keys(current_string(buf1), current_string(buf2)) is when smaller, the_same => store_string(buf3, current_string(buf1)); advance_string(buf1); when larger => store_string(buf3, current_string(buf2)); advance_string(buf2); end case; would really optimize the copying of the string slices away. package buffers is type buffer_type is private; procedure advance_string(buf: in out buffer_type); function current_string(buf: in buffer_type) return string; procedure store_string(buf: in out buffer_type, data: in string); private type buffer_type is record data: string(65536); start: positive; length: positive; -- other details omitted. end record; end buffers; package body buffers is -- details omitted. function current_string(buf: in buffer_type) return string is begin return buf.data(buf.start, buf.length); end; end buffers; Brian Hanson -- -- Brian Hanson -- brh@cray.com