comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Efficient io of arbitrary binary data.
Date: 1996/09/16
Date: 1996-09-16T00:00:00+00:00	[thread overview]
Message-ID: <323D572F.5A0F@gsfc.nasa.gov> (raw)
In-Reply-To: BRH.96Sep16002020@poplar111.cray.com


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




  reply	other threads:[~1996-09-16  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-13  0:00 Efficient io of arbitrary binary data Brian R. Hanson
1996-09-14  0:00 ` Larry Kilgallen
1996-09-16  0:00   ` Brian Hanson
1996-09-16  0:00     ` Stephen Leake [this message]
1996-09-16  0:00     ` Robert A Duff
1996-09-16  0:00     ` Larry Kilgallen
1996-09-14  0:00 ` Larry Kilgallen
1996-09-14  0:00   ` Robert Dewar
1996-09-16  0:00   ` Brian Hanson
1996-09-17  0:00   ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox