comp.lang.ada
 help / color / mirror / Atom feed
From: deccrl!caen!spool.mu.edu!darwin.sura.net!aplcen.apl.jhu.edu!ddsdx2.jhuapl .edu!dlc@bloom-beacon.mit.edu  (Dave Collard x7468)
Subject: Re: Problem with inefficiency and records with variant parts
Date: 7 Oct 92 16:15:39 GMT	[thread overview]
Message-ID: <1992Oct7.161539.9771@aplcen.apl.jhu.edu> (raw)

In <SIDOU.92Oct7130337@litsun.epfl.ch> sidou@litsun.epfl.ch (Dominique Sidou) w
rites:


>First, I want to reformulate the problem, I think it
>was not enough precise in my first post:

>Suppose:

>PACKAGE qwe IS 

>  subtype t1 is Integer;
>  type t2 is array(1..1000) of Integer;
>  type t3 is array (1..1000) of Boolean;

>  subtype st is integer range 1..3;

>  type t (s : st := 1) is record
>    case s is
>      when 1 => c1 : t1;
>      when 2 => c2 : t2;
>      when 3 => c3 : t3;
>    end case;
>  end record;

>  procedure fillt1(v1 : in out t1);
>  procedure fillt2(v2 : in out t2);
>  procedure fillt3(v3 : in out t3);
>  procedure fillt(v : in out t; s : in st);

>END qwe;

>package body qwe is

>  procedure fillt1(v1 : in out t1) is
>  begin
>    v1 := 1;
>  end fiilt1;

>  procedure fillt2(v2 : in out t2) is
>  begin
>    for i in v2'range loop
>      v2(i) := 2;
>    end loop;
>  end fillt2

>  procedure fillt3(v3 : in out t3) is
>  begin
>    for i in v2'range loop
>      v3(i) := true;
>    end loop;
>  end fillt3;

>  procedure fillt(v : in out t; s : in st) is
>  begin
>      -- ?? How can I Do ??
>      -- to cast v to v(s) and then call
>      -- the corresponding filling procedure
>      -- without any copy of a structure of
>      -- type t2 or t3.
>    case s is
>      when 1 =>
>	v := (s => 1, c1 => 0);
>        fillt1(v.c1);
>      when 2 =>
>        v := (s => 2, c2 => (others => 0)); -- useless copy to avoid !!
>        fillt1(v.c2);
>      when 3 =>
>	v := (s => 3, c3 => (others => false)); -- useless copy to avoid !!
>        fillt1(v.c3);
>    end case;
>  end fillt;
--This does not do a copy on my machine:

  procedure fillt(v : out t; s : in st) is
    ret : t(s);
  begin
    case s is
      when 1 =>
        fillt1(ret.c1);
      when 2 =>
        fillt2(ret.c2);
      when 3 =>
        fillt3(ret.c3);
    end case;
    v := ret;
  end fillt;

>end qwe;

>I think now the problem is well formulated.

>Precisions:
>1: I know that if my components were
>references it would be easy. But i have to deal
>with static structures.

>2: Working with Verdix Ada 6.0.3 on Sun4/SunOs 4.1.1

>Thanks in advance for any ideas,

>/DS.

>Sidou Dominique, Ecole Polytechnique Federale de Lausanne,
>DI-LIT-INN138, Ecublens, CH-1015 Lausanne, Suisse
>tel: 693.26.48. e-mail: sidou@litsun.epfl.ch
>--

>Sidou Dominique, Ecole Polytechnique Federale de Lausanne,
>DI-LIT-INN138, Ecublens, CH-1015 Lausanne, Suisse
>tel: 693.26.48. e-mail: sidou@litsun.epfl.ch

--Thor
dlc@ddsdx2.jhuapl.edu
collard@capsrv.jhuapl.edu

             reply	other threads:[~1992-10-07 16:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-10-07 16:15 Dave Collard x7468 [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-10-07 13:34 Problem with inefficiency and records with variant parts deccrl!caen!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu
1992-10-07 12:03 news.univie.ac.at!chx400!sicsun!disuns2!disuns2.epfl.ch!sidou
1992-10-06 15:58 Robert I. Eachus
replies disabled

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