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: Stephen Leake Subject: Re: Efficient io of arbitrary binary data. Date: 1996/09/16 Message-ID: <323D572F.5A0F@gsfc.nasa.gov>#1/1 X-Deja-AN: 181088359 references: <3239B3B2.1AE4@cray.com> <1996Sep14.153426.1@eisner> content-type: text/plain; charset=us-ascii organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.02 (Win95; I) Date: 1996-09-16T00:00:00+00:00 List-Id: Brian Hanson wrote: > [discussion of optimizers snipped] > 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; > > > 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; > Since you are trying to keep only one copy of each string, but need to pass access values for it, I would suggest you define your own string type: type String_Access is access String; type Fast_String is record Buffer : String_Access; First : NATURAL; Length : NATURAL; -- or maybe last? end record; then define all your functions with this type: function current_string(buf: in buffer_type) return Fast_String is begin return (buf.data'access, (buf.start, buf.length); end; procedure store_string (To : in buffer_type; from : in fast_string) is begin To.data (1 .. from.length) := from.buffer (from.first .. from.first + from.length - 1); end; This way, the string is never copied until you need to move it. warning: I have NOT run this code thru a compiler, so typos are probably present. > Brian Hanson > -- > -- Brian Hanson > -- brh@cray.com -- - Stephe