comp.lang.ada
 help / color / mirror / Atom feed
* Avoiding dispatching in procedure's with classwide types
@ 2016-05-28 19:01 Jeremiah
  2016-06-06  3:12 ` rieachus
  2016-06-06  3:24 ` rieachus
  0 siblings, 2 replies; 8+ messages in thread
From: Jeremiah @ 2016-05-28 19:01 UTC (permalink / 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?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-06-09  1:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-28 19:01 Avoiding dispatching in procedure's with classwide types Jeremiah
2016-06-06  3:12 ` 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

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