comp.lang.ada
 help / color / mirror / Atom feed
From: Jeremiah <jeremiah.breeden@gmail.com>
Subject: Avoiding dispatching in procedure's with classwide types
Date: Sat, 28 May 2016 12:01:35 -0700 (PDT)
Date: 2016-05-28T12:01:35-07:00	[thread overview]
Message-ID: <8af002bb-271a-4a76-b0db-097a3724f0b3@googlegroups.com> (raw)

I have a procedure that uses one tagged type (the primitive type) and a classwide type.  Normally with a classwide type parameter, you expect the internals of the procedure to dispatch on the type (I'm assuming here...could be wrong).  However, I can theoretically avoid dispatching and manually do the things I want to since both types reside in the same package.  

The upside to this I *think* is efficiency (if I use this procedure on each element of a large array I could reduce the time it takes to do all the work possibly).

The downside I can imagine is that I could possibly break how a child class of the classwide type worked because I was only making changes with the base class in mind.

That said, the procedure doesn't specify how the internals work, so the caller wouldn't even know what procedures I would use or if I would use any.  Additionally if I didn't have a procedure to do something to the data members, then I would have to mess with them directly anyways.

Kind of a small example:
procedure Class_Wide_Example
  (Target : in out Tagged_Type;  
   Source : in Base_Type'Class) 
is
begin
   --  Here I could use a function or procedure call to Get_Accessor()
   --  Something like Target.Some_Accessor := Get_Accessor(Source);
   --  In theory, descendants of Source might have some extra protection around
   --  the access value being returned and doing it as below might bypass that
   --  protection.
   Target.Some_Accessor := Source.Same_Type_Of_Accessor;
end Class_Wide_Example;

I feel like this is unsafe.  However, my actual examples can get a bit more complex, so I could see a lot of dispatching calls adding up if you have large arrays of these types all calling this procedure.  I may just be overthinking this.  

However, I wanted to see what the general thought process is.  Is it ok to avoid dispatching in a procedure with a classwide type?  If not, how do you handle scenarios where you need to manage internal private data members?


             reply	other threads:[~2016-05-28 19:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-28 19:01 Jeremiah [this message]
2016-06-06  3:12 ` Avoiding dispatching in procedure's with classwide types rieachus
2016-06-07  2:23   ` Jeremiah
2016-06-07  7:43     ` Dmitry A. Kazakov
2016-06-07 11:30       ` Jeremiah
2016-06-07 21:05         ` Randy Brukardt
2016-06-09  1:12           ` Jeremiah
2016-06-06  3:24 ` rieachus
replies disabled

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