comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Access keyword
Date: Tue, 29 Apr 2008 10:37:05 -0700 (PDT)
Date: 2008-04-29T10:37:05-07:00	[thread overview]
Message-ID: <2fac581b-8361-486b-a139-603482e9b86f@m1g2000pre.googlegroups.com> (raw)
In-Reply-To: fv79c8$lik$1@registered.motzarella.org

On Apr 29, 6:55 am, Sébastien <seb.mor...@gmail.com> wrote:
> Hi,
>
> I'd like to know if there is performance issue using the access keyword?
>
> for instance the following code:
>
> package MonTest is
>
>    type Vecteur is
>      record
>        x: Integer;
>        y: Integer;
>      end record;
>
>    function Norme(v: in Vecteur) return integer;
>    function NormeAccess(v: access Vecteur) return integer;
>
> end MonTest;
>
> package body MonTest is
>
>    function Norme(v: in Vecteur) return integer is
>      n: Integer := v.x*v.x + v.y*v.y;
>    begin
>      return n;
>    end Norme;
>
>    function NormeAccess(v: access Vecteur) return integer is
>      n: Integer := v.x*v.x + v.y*v.y;
>    begin
>      return n;
>    end NormeAccess;
>
> end MonTest;
>
> Is NormeAccess faster because I'm using access keyword?

Something to keep in mind is that "access" parameters require
additional information to be passed, in order to do accessibility
level checking.  For example, suppose the body looked like this:

   type Vec_Acc is access all Vecteur;
   Save_Vec_Acc : Vec_Acc;
   function NormeAccess(v: access Vecteur) return integer is
     n : Integer := v.x*v.x + v.y*v.y;
   begin
     Save_Vec_Acc := Vec_Acc(v);
   end NormeAccess;

Since you can't have a global access variable pointing to a local
variable belonging to some procedure, the program will have to check,
at run time, whether the "v" you passed in points to a global or
local; and this means that whoever calls NormeAccess will also have to
tell it the "accessibility level" of the access that it's passing in.
Now I realize that your NormeAccess doesn't actually do anything like
this with the access, but the compiler isn't going to know that when
it compiles the specification of MonTest, so the accessibility level
will need to be passed in somehow, regardless of whether it will be
used.  This will almost certainly use up a few extra cycles.

                                  -- Adam



  parent reply	other threads:[~2008-04-29 17:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 13:55 Access keyword Sébastien
2008-04-29 14:35 ` Peter Hermann
2008-04-29 14:43 ` Ludovic Brenta
2008-04-29 15:16 ` stefan-lucks
2008-04-29 16:31   ` Sébastien
2008-04-29 19:55     ` Gautier
2008-04-30 14:26       ` Sébastien
2008-04-30 17:13         ` Gautier
2008-04-30 20:44         ` Ludovic Brenta
2008-04-29 17:37 ` Adam Beneschan [this message]
2008-04-29 19:08 ` Jeffrey R. Carter
2008-04-29 21:03 ` Maciej Sobczak
2008-04-29 21:32 ` Randy Brukardt
2008-04-30  4:36   ` Gautier
2008-04-30  7:15   ` Maciej Sobczak
2008-04-30  7:56     ` Dmitry A. Kazakov
2008-04-30  9:21     ` Georg Bauhaus
2008-04-30 15:16     ` Adam Beneschan
2008-04-30 15:20     ` Adam Beneschan
2008-04-30 21:32       ` Maciej Sobczak
2008-04-30 21:58         ` Adam Beneschan
2008-05-01  1:10         ` Adam Beneschan
2008-04-30 23:40       ` Randy Brukardt
2008-04-30 14:32   ` Sébastien
replies disabled

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